Categories We Write About

Build a bulk image downloader

To build a bulk image downloader, you can create a simple script in Python using libraries like requests, os, and BeautifulSoup for HTML parsing. Below is a complete working script that downloads all image files (.jpg, .jpeg, .png, .gif, etc.) from a given web page URL.


Python Script: Bulk Image Downloader

python
import os import requests from bs4 import BeautifulSoup from urllib.parse import urljoin # Set the URL of the webpage to scrape url = input("Enter the webpage URL: ").strip() # Create a folder to store downloaded images output_folder = "downloaded_images" if not os.path.exists(output_folder): os.makedirs(output_folder) # Headers to simulate a browser visit headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" } try: response = requests.get(url, headers=headers) response.raise_for_status() soup = BeautifulSoup(response.text, "html.parser") images = soup.find_all("img") count = 0 for img in images: img_url = img.get("src") if not img_url: continue # Join relative URLs with base URL full_url = urljoin(url, img_url) # Get the image content img_data = requests.get(full_url, headers=headers).content img_name = os.path.join(output_folder, f"image_{count}.jpg") # Save the image with open(img_name, "wb") as f: f.write(img_data) print(f"Downloaded: {img_name}") count += 1 print(f"nTotal images downloaded: {count}") except requests.RequestException as e: print(f"Error: {e}")

💡 Features

  • Downloads all images from any public webpage.

  • Saves images in a folder named downloaded_images.

  • Automatically resolves relative image URLs.

  • Uses a user-agent to mimic browser behavior.


📦 Requirements

Install dependencies using pip:

bash
pip install requests beautifulsoup4

🔧 Optional Enhancements

  • Add file extension detection from Content-Type.

  • Filter by image size or resolution.

  • Add retry mechanism or timeout handling.

  • Download from a list of URLs (batch mode).

  • GUI with tkinter or PyQt for user interaction.

Let me know if you want it turned into a GUI app, CLI tool with options, or browser extension.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About