You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hnu202111020408 7b910015ac
Update README.md
4 years ago
README.md Update README.md 4 years ago

README.md

import requests import json import urllib import os headers = {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"} url="https://image.baidu.com/search/acjson?tn=resultjson_com&logid=10733082029176239585&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E5%B7%A5%E7%A8%8B%E5%B8%88&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=0&hd=&latest=&copyright=&word=%E5%B7%A5%E7%A8%8B%E5%B8%88&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&expermode=&force=&pn=30&rn=30&gsm=1e&1610277680854=" imgs= requests.get(url,headers=headers,timeout=1) imgs.encoding='utf-8' data = json.loads(imgs.text) imgdatas = data['data'] imgs_url=[] for i in imgdatas: if 'thumbURL' in i.keys():
imgs_url.append(i['thumbURL']) else: continue a=os.path.exists('/root/imgs4') if not a: os.mkdir('/root/imgs4') m=0 for img_url in imgs_url: flag=True try: urllib.request.urlretrieve(img_url, "/root/imgs4" + str(m) + '.jpg') except BaseException: flag=False if(flag): print('**第'+str(m+1)+'张图片下载完成') m = m + 1 if m==20: break print('下载完成!')