import requests
url = 'https://www.sogou.com/'
response = requests.get(url=url)
page_text = response.text
with open('./sougou.html', 'w', encoding='utf-8') as fp:
fp.write(page_text)
import requests
keyWord = input('enter a key word: ')
params = {
'query': keyWord
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}
url = 'https://www.sogou.com/web'
response = requests.get(url=url, params=params, headers=headers)
response.encoding = response.apparent_encoding
fileName = keyWord + '.html'
page_text = response.text
with open(fileName, 'w', encoding='utf-8') as fp:
fp.write(page_text)
print(fileName,"爬取完毕!")