不废话了,直接上代码:
import re
import os
import requests
import tqdm
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'}
def getImg(url,idx,path):
img=requests.get(url,headers=header)
file=open(path+str(idx)+'.jpg','wb')
file.write(img.content)
file.close()
search=input("请输入搜索内容:")
number=int(input("请输入需求数量:"))
path='image/'+search+'/'
if not os.path.exists(path):
os.makedirs(path)
bar=tqdm.tqdm(total=number)
page=0
while(True):
if number==0:
break
url = 'https://image.baidu.com/search/acjson'
params={
"tn": "resultjson_com",
"logid": "11555092689241190059",
"ipn": "rj",