Skip to content

Instantly share code, notes, and snippets.

@subhajeet2107
Created May 4, 2019 14:22
Show Gist options
  • Save subhajeet2107/c239c52d63f6cacf5d8e12ec53548e3c to your computer and use it in GitHub Desktop.
Save subhajeet2107/c239c52d63f6cacf5d8e12ec53548e3c to your computer and use it in GitHub Desktop.
Download images and stores in nested folders
#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