import requests
headers={
"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.82"
}
url="https://www.sogou.com/sogou?"
kw=input("请输入搜索内容:")
dict={
"query":kw
}
response=requests.get(url=url,params=dict,headers=headers)
text=response.text
filename=kw+'.html'
with open(filename,"w",encoding="utf-8") as f:
f.write(text)
print(filename+"保存成功")
1、指定url
2、发送请求
3、获取响应数据
4、持久化存储