pycharm利用request请求百度搜索关键词并读取源码下载到本地


import
requests params = { 'wd' : 'seo' } headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' } response = requests.get("http://www.baidu.com/s",params=params,headers=headers) with open('baidu.html','w',encoding='utf-8') as fp: fp.write(response.content.decode('utf-8')) print(response.url)

执行结果如下:

下载下来的baidu.html文件

pycharm利用request请求百度搜索关键词并读取源码下载到本地_第1张图片

 

转载于:https://www.cnblogs.com/secsafe/p/11186178.html

你可能感兴趣的:(pycharm利用request请求百度搜索关键词并读取源码下载到本地)