import urllib.request import re import os import urllib import json def createFileFolder(i): # 获取当前绝对地址 path = os.path.abspath('.') # 拼接新地址 path = os.path.join(path,str(i)) # 创建文件夹 os.mkdir(path) return path def getImg(index): # 读取json文件 fp = open('./allData.json') data = json.load(fp) folder_url = '' for url in data: print('当前index%s'%(index)) if index < 5000: index += 1 continue if index%500 == 0: folder_url = createFileFolder(int(index/500)) img_url = os.path.join(folder_url,str(index%500)+'.jpg') urllib.request.urlretrieve(url, img_url) print('%s下载完成'%(img_url)) index += 1 getImg(0)