度娘识图扫一扫入口 度娘识图app下载|度娘识图软件下载v1.0.0安卓版
记得要加上headers,否则会报错,被认为是爬虫。
import requestsimport jsonimport randomimport stringimport osword=input("请输入关键词:")print(word)max_value=100current_value=0i=0headers={'User-Agent':"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}while current_value<max_value: url=f"https://image.baidu.com/search/acjson?tn=resultjson_com&logid=10080522294965570219&ipn=rj&ct=201326592&is=&fp=result&fr=&word={word}&queryWord=%E5%A4%96%E6%98%9F%E4%BA%BA&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=?right=&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&expermode=&nojc=&isAsync=&pn={current_value}&rn=30&gsm=1e&1706710087306=" result=requests.get(url,headers=headers) json_str=result.content json_doc=str(json_str,'utf-8') imageResult=json.loads(json_doc) print(imageResult) data=imageResult['data'] for record in data: url=record.get('middleURL') if url!=None: print('正在下载图片:',url) r=requests.get(url) with open(fr"C:\xx\xxx\xxxxx\xxxxx\百度搜索图片\{i}.jpg",'wb') as f: f.write(r.content) f.close() i+=1 current_value+=30