为什么使用了UA伪装,还是异常访问请求啊?(我用的是火狐浏览器打开的jupyter notebook)


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 爬取成功!

img

访问过快,过多