Last active
February 1, 2017 06:37
-
-
Save SuperShinyEyes/8ca4b1ab33446f2a3e8fad3e5a7e2d9a to your computer and use it in GitHub Desktop.
Download JPGs by reading a file of image URLs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Python3 | |
import requests | |
PATH_PREFIX = "" | |
FILE = "imageNames" | |
def downloadImage(url): | |
''' | |
Reference: | |
http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests | |
''' | |
name = url.split("/")[-1] | |
path = PATH_PREFIX + name | |
r = requests.get(url, stream=True) | |
if r.status_code == 200: | |
print("Write %s" % path) | |
with open(path, 'wb') as f: | |
for chunk in r: | |
f.write(chunk) | |
else: | |
print("No write") | |
with open(FILE) as f: | |
# Remove newlines | |
for url in f.read().splitlines(): | |
print(url) | |
downloadImage(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment