keyword=input('输入一个关键词')
headers={
'user_agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0'
}
params={
'query':keyword
}
url='https://www.sogou.com/web'
response=requests.get(url=url,params=params,headers=headers)
response.encoding='utf-8'
page_text=response.text
fileName=keyword+'.html'
with open (fileName,'w',encoding='utf-8') as fp:
fp.write(page_text)
print(fileName,'爬取成功!')
输出:
输入一个关键词jay
jay.html 爬取成功!
访问过快,过多