url = 'https://www.sogou.com/web?'
KeyWord = input('Please input:')
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
}
params = {
'query':KeyWord
}
res = requests.get(url=url, headers= headers, params=params)
res.encoding = 'utf-8'
page_text = res.text
# print(res.text)
FileName = KeyWord + '.html'
with open(FileName, 'w', encoding= 'utf-8') as f:
f.write(page_text)
这是一个爬搜狗的 KeyWord如果是字符串,就是在搜狗页面单纯搜索KeyWord,如果是value值就是搜索input输出的字符串 我不太懂这个地方 |