A simple Python script to download all images from a given webpage.
Works on Linux, macOS, and Windows Subsystem for Linux (WSL).
- Extract images from HTML
<img>tags (including srcset) and CSSurl()styles - Support for custom HTTP headers
- Progress tracking with completion percentage
- Skip existing images (optional re-download with flag)
- Custom download folder location
- Handles relative and absolute URLs
- Choose a specific image from a
srcsetor fallback to first/last option
git clone https://github.com/jasperalani/image-downloader.git
cd image-downloaderFirst, make sure Python 3 is installed.
- If using Windows WSL as your linux environment then you might have to create a local python environment:
python3 -m venv ~/python_custom_env
~/python_custom_env/bin/pip3 install requests beautifulsoup4 tqdm- If using other Linux/Mac:
pip install requests beautifulsoup4 tqdm- Windows WSL:
~/python_custom_env/bin/python3 image-downloader.py https://example.com- Linux/Mac:
python3 image-downloader.py https://example.comReplace https://example.com with the URL of the page you want to download images from.
| Argument | Description |
|---|---|
website |
Website URL to scrape images from (required) |
-f, --folder |
Folder location to download images (default: ./download) |
-r, --redownload |
Redownload images that pre-exist in download folder |
-d, --headers |
Custom headers in JSON format |
-t, --timeout |
Request timeout in seconds (default: 10) |
-c, --srcset |
Index of image to use from srcset (0-based index) |
-cf, --srcset-use-first |
Fallback to first image in srcset if index is out of range (default: true). Set to false to fallback to the last image instead. |
Download images to default folder:
image-downloader https://example.comDownload to a specific folder:
image-downloader https://example.com -f ./my_imagesForce redownload of existing images:
image-downloader https://example.com -rUse custom headers:
image-downloader https://example.com -d '{"User-Agent": "Custom Agent", "Referer": "https://example.com"}'Set custom timeout:
image-downloader https://example.com -t 30Use 4th image from srcset, and fallback to last image if out of range:
image-downloader https://example.com -c 4 -cf false