根據(jù)url圖片下載不下來,這些url是要下載ImageNet數(shù)據(jù)集里的數(shù)據(jù),圖片都是國外的是,所以連接超級慢,有一些圖片已經(jīng)丟失了。想問一下該怎么下載才能盡可能把圖片又好又快的下載到我的電腦我的代碼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()
根據(jù)url下載圖片?
無無法師
2018-05-12 09:27:41