A Python web scraper that automatically downloads images from websites using Selenium and requests libraries.
- 🤖 Headless Chrome browsing for stealthy scraping
- 📸 Downloads images from dynamic web pages
- 🔄 Infinite scroll support to load more content
- 📊 Detailed download statistics
- 🎯 Avoids duplicate downloads
- 🕵️ Mimics human behavior with random delays
Before running the scraper, you need to install these dependencies:
pip install selenium requestsYou also need to have Chrome browser installed on your system. The scraper uses ChromeDriver which is automatically managed by Selenium.
- Configure the scraper: Edit the
scraper_img.pyfile to set your target website and output directory:
# Configuration
WEBSITE_URL = "https://www.example.com/"
OUTPUT_DIR = r"D:\path\to\save\images"- Run the scraper:
python scraper_img.pyYou can customize these parameters in the script:
max_scrolls: Maximum number of scroll attempts (default: 7)scroll_delay: Delay between scrolls (default: 3 seconds)no_new_images_threshold: Stop if no new images for this many consecutive scrolls (default: 3)random delays: Between 0.5-2 seconds between downloads to mimic human behavior
- Initialization: Sets up headless Chrome browser with stealthy user agent
- Page Access: Navigates to the target website
- Infinite Scroll: Scrolls down to load more content
- Image Collection: Extracts all unique image URLs
- Download: Downloads images to the specified directory
- Cleanup: Properly closes the browser
Accessing website: https://www.example.com/
Starting limited scroll for testing...
Maximum scroll attempts: 7
Stop if no new images for: 3 consecutive scrolls
Scroll 1: Found 25 new images (Total: 25)
Scroll 2: Found 18 new images (Total: 43)
Scroll 3: No new images (1/3 consecutive)
Scroll 4: No new images (2/3 consecutive)
Scroll 5: No new images (3/3 consecutive)
Stopping: No new images for 3 consecutive scrolls
Total unique images found: 43
Scrolling complete! Total unique images: 43
Starting to download 43 images...
Downloading: image1.jpg (1/43)
Successfully downloaded: image1.jpg (1/43)
Downloading: image2.jpg (2/43)
Successfully downloaded: image2.jpg (2/43)
==================================================
Download Summary:
Total images found: 43
Successfully downloaded: 41
Failed: 2
Skipped (existing): 0
==================================================
Browser closed.
- Respect website's robots.txt file and terms of service
- Use appropriate delays to avoid overwhelming servers
- The scraper may not work on websites with strong anti-bot measures
- Always use this tool responsibly and ethically
MIT License - feel free to use this tool for learning purposes.