How to Take Website Screenshots with Python (3 Methods Compared)

April 11, 2026

Need to capture a website screenshot from a Python script? There are three main approaches, each with different tradeoffs. Here's a practical comparison so you can pick the right one.

Method 1: Selenium + ChromeDriver

The classic approach. Selenium controls a real browser instance.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

driver = webdriver.Chrome(options=options)
driver.set_window_size(1280, 720)
driver.get("https://example.com")
driver.save_screenshot("screenshot.png")
driver.quit()

Pros: Full browser automation, can interact with pages before capture.
Cons: Requires ChromeDriver binary, version matching headaches, heavy resource usage (~300 MB RAM), flaky in CI/CD environments, slow startup.

Method 2: Playwright

Modern alternative to Selenium. Better API, built-in browser management.

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 1280, "height": 720})
    page.goto("https://example.com")
    page.screenshot(path="screenshot.png")
    browser.close()

Pros: Cleaner API, auto-manages browser binaries, better waiting strategies.
Cons: Still runs a full browser (~200 MB RAM), requires playwright install to download Chromium, adds ~400 MB to your Docker image.

Method 3: Screenshot API

Offload the browser entirely. One HTTP request, screenshot back.

import requests

resp = requests.post(
    "https://screenshotapis.org/v1/screenshot",
    headers={"X-Api-Key": "sk_live_your_key"},
    json={"url": "https://example.com", "format": "png"},
)
with open("screenshot.png", "wb") as f:
    f.write(resp.content)

Pros: No browser to install or manage, works in any environment (Lambda, Cloud Functions, minimal containers), sub-second response, 5 lines of code.
Cons: Requires API key (free tier: 100 renders/month), external dependency.

Which should you use?

Criteria Selenium Playwright API
Setup complexityHigh MediumNone
Memory usage~300 MB ~200 MB0
Docker friendlyPainful OkayYes
Page interactionFull FullLimited
Best forE2E testing AutomationScreenshots at scale

Use Selenium or Playwright when you need to interact with the page (click buttons, fill forms) before capturing. Use an API when you just need the screenshot — it's faster to implement, uses zero server resources, and scales without infrastructure.

Skip the browser setup. Get screenshots with one API call.

Get your API key — free