Take Screenshots of a List of URLs Using Python
In this article
- 1. Selenium with WebDriver
- 2. Playwright (Python)
- 3. Pyppeteer (Puppeteer port)
- 4. wkhtmltoimage (via subprocess)
- 5. Selenium Grid for Parallel Captures
- 6. Using Requests + imgkit (wkhtmltoimage wrapper)
- 7. Headless Chrome with --screenshot Flag
- 8. Pillow for Post-Processing
- 9. Using PyAutoGUI for Legacy Apps
- 10. Cloud Services (Screenshotone, Urlbox)
- How to Choose
- Frequently Asked Questions
- Final Thoughts
This guide covers practical Python methods for taking screenshots of multiple URLs automatically. Whether you're auditing web pages, creating visual documentation, or monitoring changes, these tools save hours of manual work. You'll find options for simple command-line use, browser automation, and headless environments—each with real code examples you can adapt immediately.
1. Selenium with WebDriver
Selenium is the most flexible option because it drives a real browser (Chrome, Firefox, Edge). You can capture full-page screenshots, handle JavaScript-heavy sites, and interact with elements before capturing. Use driver.set_window_size() to set a large viewport, then driver.save_screenshot() for each URL. It's ideal when you need to log in, click through modals, or wait for dynamic content to load.
2. Playwright (Python)
Playwright is a modern alternative with built-in support for full-page screenshots via page.screenshot(full_page=True). It automatically waits for network idle and can emulate mobile devices, which is great for responsive design checks. Its API is cleaner than Selenium's, and it runs headless by default, making it faster for bulk captures. You can also capture specific elements or set custom viewport sizes per URL.
3. Pyppeteer (Puppeteer port)
Pyppeteer is an unofficial Python port of Puppeteer, using Chromium under the hood. It's lightweight and works well for simple screenshot tasks without the overhead of a full browser driver. You can launch a browser, iterate through URLs, and use page.screenshot() with options like fullPage and type. Be aware that it's not as actively maintained as Playwright, but it's still reliable for basic needs.
4. wkhtmltoimage (via subprocess)
wkhtmltoimage is a command-line tool that converts HTML to an image using the Qt WebKit engine. It's fast and doesn't require a browser driver, making it perfect for simple static pages. You can call it from Python using subprocess.run(), passing the URL and output filename. It supports custom window sizes via --width and --height, but it may not render modern CSS or JavaScript perfectly.
5. Selenium Grid for Parallel Captures
If you have many URLs, running Selenium in parallel speeds things up dramatically. Selenium Grid lets you distribute tests across multiple machines or browsers. You can write a Python script that uses concurrent.futures to launch multiple WebDriver instances, each handling a subset of URLs. This approach is more complex to set up but scales well for hundreds or thousands of URLs.
6. Using Requests + imgkit (wkhtmltoimage wrapper)
imgkit is a Python wrapper for wkhtmltoimage that simplifies the subprocess calls. You can pass a list of URLs, set options like format and quality, and get images directly. It's a good middle ground if you want a Pythonic interface without learning browser automation. Note that it inherits wkhtmltoimage's rendering limitations.
7. Headless Chrome with --screenshot Flag
Chrome itself can take screenshots from the command line: chrome --headless --screenshot=output.png --window-size=1280,720 URL. You can call this from Python via subprocess for each URL. It's extremely fast and doesn't require any extra libraries. However, it only captures the viewport, not the full page, and you'll need to handle browser path differences across operating systems.
8. Pillow for Post-Processing
Once you have screenshots, Pillow (PIL) helps you combine, crop, or annotate them. For example, you can create a contact sheet of all URLs for a quick visual overview. Use Image.open() to load each file, then paste() onto a new canvas. This is useful for generating reports or comparing versions side-by-side.
9. Using PyAutoGUI for Legacy Apps
If you need to capture a desktop application or a page that requires manual interaction, PyAutoGUI can take full-screen or region-specific screenshots. It simulates mouse and keyboard actions, so you can automate clicking through a list of URLs in a browser and capture each one. This approach is slower and fragile, but it works when other methods fail due to authentication or captchas.
10. Cloud Services (Screenshotone, Urlbox)
For high-volume or always-on needs, cloud screenshot APIs like Screenshotone or Urlbox offer REST endpoints. You send a URL and receive a PNG/JPEG back. They handle scaling, rendering, and storage, and you can call them from Python using requests.get(). This is a paid option but saves local resources and works with complex sites reliably.
How to Choose
First, consider your page complexity: if sites are static, wkhtmltoimage or Chrome headless is sufficient. If they rely heavily on JavaScript, use Selenium or Playwright. For speed, Playwright and Chrome headless are faster than Selenium. For parallel processing, Selenium Grid or Playwright's async API are best. Finally, think about maintenance—Playwright has better long-term support than Pyppeteer, and cloud services reduce local setup but add cost.
Frequently Asked Questions
Q: Can I capture full-page screenshots with Selenium?
A: Yes, set a large window size (e.g., 1920x1080) and use driver.save_screenshot(), but it only captures the viewport. For full-page, you need to scroll and stitch, or use Playwright's built-in full_page=True.
Q: How do I handle pages that require login?
A: Use Selenium or Playwright to automate login once, then reuse the session (cookies) for subsequent URLs. You can save cookies with get_cookies() and load them later.
Q: What's the fastest method for 100+ URLs?
A: Playwright's async API or Selenium Grid with parallel workers. Chrome headless via subprocess is also fast but lacks full-page support.
Q: Are there free cloud options?
A: Some services offer free tiers (e.g., Screenshotone has a limited free plan), but they usually have quotas. For unlimited free, stick to local tools like Playwright.
Q: Can I capture screenshots in a Docker container?
A: Yes, use a Docker image with Chromium and Playwright or Selenium. Ensure you install the necessary system dependencies like libglib2.0-0 and fonts.
Q: How do I avoid getting blocked by anti-bot systems?
A: Use realistic user agents, add delays between requests, and consider using a proxy rotation. Playwright can mimic human behavior with page.mouse.move() and random waits.
Final Thoughts
Automating screenshots with Python is straightforward once you pick the right tool. For most modern websites, Playwright offers the best balance of features and ease. Start with a small list, test on a few URLs, and scale up. Remember to handle timeouts and errors gracefully—your script should skip failed URLs and continue.