Skip to content

Instantly share code, notes, and snippets.

@IvanKuteynikov
Forked from davidbauer/gist:11055010
Last active November 24, 2017 19:24
Show Gist options
  • Save IvanKuteynikov/0bfe2f7467cb103e66c3c367ae6da0eb to your computer and use it in GitHub Desktop.
Save IvanKuteynikov/0bfe2f7467cb103e66c3c367ae6da0eb to your computer and use it in GitHub Desktop.
Python script to download images from a CSV of image urls
#!/usr/bin/env python
# assuming a csv file with a name in column 0 and the image url in column 1
import urllib
filename = "images"
# open file to read
with open("{0}.csv".format(filename), 'r') as csvfile:
# iterate on all lines
i = 0
for line in csvfile:
splitted_line = line.split(',')
# check if we have an image URL
if splitted_line[1] != '' and splitted_line[1] != "\n":
urllib.urlretrieve(splitted_line[1], "img_" + "{0:03}".format(i) + ".png")
print "Image saved for {0}".format(splitted_line[0])
i += 1
else:
print "No result for {0}".format(splitted_line[0])
@IvanKuteynikov
Copy link
Author

Thanks, very useful.
change line 17, now filenames will have 3 digits numbers, 000-009,010-100 and etc, it's important for arrange by names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment