#requests库爬取图片
import requests
from bs4 import BeautifulSoup
def spider():
url='https://www.sogou.com/web'
keyword=input('请输入信息')
headers={
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.30'
}
pagarm={'query':keyword}
html=requests.get(url=url,params=pagarm,headers=headers)
htmltxt=html.text
#filename=keword+'.html'
fnew=open('F:/spidertest/'+keyword+'.txt','a',encoding='utf-8')
fnew.write(htmltxt)
fnew.close()
print('保存成功')
spider()
标签:fnew,keyword,url,爬取,headers,html,requests,图片
From: https://www.cnblogs.com/tgfoven/p/17105400.html