A flexible Python script to scrape image URLs from any website using Selenium. Just plug in your target URL and CSS selector, and it will fetch image sources with a headless Chrome browser.
- Headless Chrome automation
- Scrapes
<img>tags or any image-containing elements - Works on any site β just update the URL and selector
- Clean and configurable
- Python 3.7+
- Google Chrome
- ChromeDriver (matching your Chrome version)
- Selenium
pip install seleniumUse this helper script or install via package manager:
Ubuntu/Debian:
sudo apt install -y chromium-browser chromium-chromedrivermacOS (Homebrew):
brew install --cask google-chrome
brew install chromedriverNote: Make sure
chromedriveris in your system'sPATH. You can verify with:
which chromedriverUpdate the script with your:
- Target URL
- Image CSS selector (defaults to standard
<img>tags)
Example snippet to modify:
search_url = "https://example.com/images"
img_elements = driver.find_elements(By.CSS_SELECTOR, "img") # or your custom selectorRun the script:
python main.pyIt will prompt you for a URL, open it in a headless browser, and return a list of image URLs.
Example:
Enter page URL: https://example.com/gallery
Image 1: https://...
Image 2: https://...
Image 3: https://...
def fetch_image_urls(url, selector="img", max_results=3):
# Your scraping logic here.photo-class imgβ nested imagesdiv.gallery imgβ within specific containersimg.thumbnailβ specific class-based images
.
βββ main.py # Main script
- Be respectful of website terms of service.
- This is for educational or authorized use only.
- Some sites may use lazy-loading or dynamic content (use
driver.execute_script()or scroll automation if needed).