例如对搜狗浏览器搜索“画家”实现如下:
import requestsURL = "/web" #UA伪装header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67'}#参数param = {'query':'画家'}#发起请求response = requests.get(url = URL,headers = header,params = param)#获取响应数据page_ = response.text#保存文件with open('画家.html','w',encoding = 'utf-8') as fp:fp.write(page_)print("保存成功")
效果如下