爬虫实战之简易网页收集器具体代码如下:
import requests
if __name__ == '__main__':
header={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}
url='https://www.sogou.com/web'
a=input('请输入内容')
param={
'query':a
}
response=requests.get(url=url,params=param,headers=header)
page=response.text
print(page)
fileName=a+'.html'
with open(fileName,'w',encoding='utf-8') as fp:
fp.write(page)
print(fileName,'保存数据')