概述
import requests
import json
base_url = "http://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp="
"result&queryWord=%E7%8C%AB&cl=2&lm=&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=&"
"copyright=&word=%E7%8C%AB&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&expermode=&"
"force=&pn={}&rn=30&gsm=3c&1586780971519="
referer = "http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=&st=-1&fm=result&"
"fr=&sf=1&fmq=1586774219869_R&pv=&ic=&nc=1&z=&hd=&latest=©right=&se=1&showtab=0&fb=0&width=&"
"height=&face=0&istype=2&ie=utf-8&sid=&word=%E7%8C%AB"
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/80.0.3987.106 Safari/537.36", "Referer":referer}
index = 1
for i in range(1, 16):
url = base_url.format(str(i * 30))
response_1 = requests.get(url)
js_data = json.loads(response_1.text)
for j in range(0, 30):
img_url = js_data["data"][j]["thumbURL"]
print(img_url, index, sep=" ")
response_2 = requests.get(img_url, headers=header)
if index == 430:
print(response_2.status_code)
if response_2.status_code == 200:
with open("/home/yan/jupyter_notebook_file/Neural_Network/baidu_image_cat_dataset/cat_" + str(index) + ".jpg",
'wb') as f:
f.write(response_2.content)
f.close()
index += 1
else:
print("Warning:403")
最后
以上就是感动雪碧为你收集整理的爬取百度图片450张猫图片的全部内容,希望文章能够帮你解决爬取百度图片450张猫图片所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复