Created
May 4, 2019 14:22
-
-
Save subhajeet2107/c239c52d63f6cacf5d8e12ec53548e3c to your computer and use it in GitHub Desktop.
Download images and stores in nested folders
This file contains 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
#Download images | |
from pathlib import Path | |
import shutil, os, requests | |
urls = [] | |
for url in urls: | |
r = requests.get(url, stream=True) | |
image_path = url.replace('https://www.somedomain.com/images/','') | |
path = Path('/assets/images/' + image_path) | |
path.parent.mkdir(parents=True, exist_ok=True) | |
with open(path, 'wb') as f: | |
r.raw.decode_content = True | |
shutil.copyfileobj(r.raw, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment