#原创
更新日期:2021/02/15
如果觉得能够节省您抓包的时间,哪怕打赏0.1也是爱呀,嘿嘿!
import requests
import json
def search_baidu_image(key,num=4):
'''
百度图片爬虫
:param key: 关键词
:param num: 页面数,一页最多30张
:return: 有数据返回数据,没数据返回None
'''
url='https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&word='+quote(key)+'&pn='+str(num*30)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
}
resp=requests.get(url,headers=headers)
try:
return json.loads(resp.content.decode())
except:
return None