爬虫简单应用百度搜索,可输入

import requests

url = 'https://www.sogou.com/web'
kw = input('enter a word:')
# 可输入内容,查询
param = {
    'query':kw
}
# 模拟浏览器
headers={
        "User-Agent": "Mozilla / 5.0(Windows NT 6.1;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 85.0.4183.83Safari / 537.36"
    }

response = requests.get(url=url,params=param,headers=headers)
page_text = response.text
# 将搜索结果保存到本地
filename = kw + '.html'
with open(filename,'w',encoding='utf-8') as fp:
    fp.write(page_text)

print(filename,'保存成gong')

你可能感兴趣的:(爬虫,爬虫)