Created
October 30, 2019 10:30
-
-
Save YaYaB/c4abb2ef4c54b3cfd1f007f0b69db88e to your computer and use it in GitHub Desktop.
Download an image from url
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
import urllib.request | |
import shutil | |
def downloader(image_url, basename, index=None): | |
req = urllib.request.Request(image_url, headers={'User-Agent': 'Mozilla/5.0'}) | |
if index: | |
full_file_name = basename + '-' + str(index) + '.jpg' | |
else: | |
full_file_name = basename + '.jpg' | |
with urllib.request.urlopen(req) as response, open(full_file_name, 'wb') as out_file: | |
shutil.copyfileobj(response, out_file) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment