使用Urllib时,如何使用CSV文件中的第二列命名图像文件?
我有要在CSV文件中下载的100张图像的列表。 CSV上没有标题。第一列具有图像的位置,第二列的名称我希望将图像保存为。
我正在使用urllib
下载图像。我想为循环设置,该循环使用第一列中的位置,并从第二列中的数据命名。我在这里放了的行是错误的,但是希望您能得到这个想法 -
urllib.request.urlretrieve('url [0]','url [1]')
- 我正在尝试拉动从第一列或第二列。
urls = []
f = open('multicoltest.csv', encoding='utf-8-sig')
csv_f = csv.reader(f)
for row in csv_f:
urls.append(row[0])
f.close()
for url in urls:
urllib.request.urlretrieve('url[0]', 'url[1]')
I have a list of 100 images I want to download in a CSV file. There are no headers on the CSV. The first column has the location of the image and the second column has the name I would like the image saved as.
I am using urllib
to download the images. I would like to setup a for
loop which uses the location from the first column and names it from the data in the second column. The line I put in here is wrong, but hopefully you get the idea - urllib.request.urlretrieve('url[0]', 'url[1]')
- I'm trying to pull from the first or second column.
urls = []
f = open('multicoltest.csv', encoding='utf-8-sig')
csv_f = csv.reader(f)
for row in csv_f:
urls.append(row[0])
f.close()
for url in urls:
urllib.request.urlretrieve('url[0]', 'url[1]')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以一次执行一行,而无需首先阅读整个文件:
You can do it a line at a time without reading the entire file first: