本人目前情况如下:
很明显,这里需要用到循环,因此我的代码如下:
import csv #加载csv包便于读取csv文件
import requests
with open ('vehicles.csv','r',encoding = 'utf-8') as csvfile:
reader = csv.reader(csvfile)
links = [row[1] for row in reader]
for link in links:
imgresponse = requests.get(link, stream=True) #以流的方式打开
image = imgresponse.content
address="H:\程序语言学习用文件夹\Python\images"+"\\" #保存地址
i = 1
try:
with open(address+"{0}".format(i) ,"wb") as jpg:
jpg.write(image)
i = i + 1
except IOError:
print("IO Error\n")
finally:
jpg.close
然而实际情况是,控制台没有报错,但图片只下载了一张,就是最后一张,而且它还被命名成了“1”??!!