soso指定关键字页面搜索内容爬取

import requests

url = 'https://www.sogou.com/tx?ie=utf8&pid=&'

UA伪装

headers = {
'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36'
}

设定搜索关键字变量

kw = input('enter a word:')
param = {
'query':kw
}

发起请求

response = requests.get(url=url,params=param,headers=headers)

获取

page_test = response.text

保存数据

fileName = kw+'.html'
with open(fileName,'w',encoding='utf-8') as fp:
fp.write(page_test)
print(fileName,'保存成功!!!')

posted @ 2022-02-25 14:23  Ryan-liang  阅读(60)  评论(0编辑  收藏  举报