import csv
import numpy as np
import requests
data=[]
with open('imageURL.csv', 'r') as f: # 读取图片地址
reader = csv.reader(f)
for row in reader:
data.append(row)
proxies = {
"http": "http://127.0.0.1:1080",
"https": "http://127.0.0.1:1080",
}
errNum=[]
doneNum=[]
for i in range(len(data)):
item=data[i]
try:
response = requests.get(item[0], proxies=proxies,timeout=3)
if response.status_code == requests.codes.ok:
with open("trainimgs/"+item[2], "wb") as code:
code.write(response.content)
doneNum.append(i)
print("i:",i," done:",item[0])
else:
print("i:",i," Err:",item[0])
errNum.append(i)
except:
print("i:",i," Err:",item[0])
errNum.append(i)
continue
python 使用代理批量下载网络图片
最新推荐文章于 2023-05-30 15:47:48 发布