根据url图片下载不下来,这些url是要下载ImageNet数据集里的数据,图片都是国外的是,所以连接超级慢,有一些图片已经丢失了。想问一下该怎么下载才能尽可能把图片又好又快的下载到我的电脑
我的代码
import urllib.request path="G:\\grabage_pragram\\ImageNet" read_path=path+"\\"+"newspaper.txt" down_url="G:\\grabage_pragram\\ImageNet\\newspaper_down\\" count=0 bad_count=0 f = open(read_path,'r',encoding="utf-8") print(f.readline()) line=f.readline() while line: print(count) url=line print(url) image_type=url.split('.')[-1] name=down_url+str(count)+"."+image_type try: conn = urllib.request.urlopen(url) ff = open(name,"wb") ff.write(conn.read()) ff.close() count=count+1 except: bad_count=bad_count+1 print("error"+str(bad_count)) line=f.readline() f.close()