|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
keyword = input('请输入您需要搜索的key word:')
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'
}
params ={
'keys':'keyword'
}
url = 'https://www.sogou.com/web?'
response = requests.get(url=url,params=params,headers=headers)
response.encoding = 'utf-8'
page_text = response.text
# print(page_text)
fileName = keyword+'.html'
with open(fileName,'w',encoding='utf-8') as f:
f.write(page_text)
print(fileName,'爬取完毕!!!')
想知道输入关键词之后没有得到相应的内容?求大佬指教
你的 params keyword 改成 query ,然后你把 keyword 变量用引号引起来了
参考代码:
import requests
keyword = input('请输入您需要搜索的key word:')
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'
}
params ={
'query':keyword
}
url = 'https://www.sogou.com/web?'
response = requests.get(url=url,params=params,headers=headers)
response.encoding = 'utf-8'
page_text = response.text
# print(page_text)
fileName = keyword+'.html'
with open(fileName,'w',encoding='utf-8') as f:
f.write(page_text)
print(fileName,'爬取完毕!!!')
|
-
-
|