import requests if __name__ == '__main__': #进行UA伪装 headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69"} url = "https://www.sogou.com/web?" #处理url所携带的参数,封装到字典中 kw = input("输入你想搜索的关键词") param = {"query":kw} #对指定的url发起请求,对应的url是携带参数的,并且在请求过程中处理了参数 response = requests.get(url=url,params=param,headers=headers) #地址,关键词,ua伪装 page_text = response.text filename = kw+'.html' with open(filename,'w',encoding = 'utf-8') as fp: fp.write(page_text) print(filename,'保存成功')
requests学习 指定关键词的搜狗页面
于 2022-01-22 23:22:27 首次发布