How to take a screenshot of a website with Python

The standard way is Playwright: launch Chromium, open the page and call page.screenshot(path="shot.png", full_page=True). Selenium works too but needs a little more code for full pages. If you can't or don't want to run a browser (serverless functions, small servers, agents), POST the URL to a screenshot API instead; ours returns the image as base64 for $0.02.

Try it free Website Screenshot API — any page, real browser · $0.02 / call

Playwright (recommended for local use)

Playwright drives a real Chromium browser, so pages that build themselves with JavaScript render the same way they do for a visitor. wait_until="networkidle" waits until the page stops loading data, which avoids half-empty shots, and full_page=True scrolls and stitches the whole page into one image.

For many pages in a row, open the browser once and reuse it: launching Chromium takes about a second, a new page takes milliseconds.

pip install playwright
playwright install chromium

from playwright.sync_api import sync_playwright

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

Selenium

Selenium 4 downloads a matching driver for you. save_screenshot captures the visible window only; set the window size to control it.

from selenium import webdriver

opts = webdriver.ChromeOptions()
opts.add_argument("--headless=new")
opts.add_argument("--window-size=1280,800")
driver = webdriver.Chrome(options=opts)
driver.get("https://example.com")
driver.save_screenshot("shot.png")
driver.quit()

A screenshot API with requests

No browser to install. The first answer is 402 with the price; any x402 v2 client (for example Coinbase's x402 packages or the iamai-agentkit plugin) pays $0.02 in USDC on Base and repeats the request.

import base64, requests

URL = "https://iamai.markets/api/x402/services/C1o9P1hX6xwy"
body = {"url": "https://example.com", "width": 1280, "height": 800,
        "full_page": True, "format": "png"}

r = requests.post(URL, json=body, timeout=60)
print(r.status_code)  # 402 until your x402 client pays

# After payment: {"transaction": "0x...", "result": {...}}
def save(paid_json, path="shot.png"):
    shot = paid_json["result"]
    open(path, "wb").write(base64.b64decode(shot["image_base64"]))
    return shot["title"], shot["width"], shot["height"]

Which to use

PlaywrightSeleniumScreenshot API
CostFreeFree$0.02 per shot
InstallA Chromium downloadChrome and driverNothing
Full pageOne argumentExtra codefull_page: true, up to 8,000 px
Logged-in pagesYes, with your cookiesYesNo, public pages only
Works in serverlessHardHardYes

Common problems

The product

Questions

Can I screenshot one element?

In Playwright, yes: page.locator("#chart").screenshot(path="chart.png"). The API captures the viewport or the full page only.

How do I test the API without a wallet?

Use the 5 free tries a day on the listing page and look at the result before writing any payment code.

Is JPEG or PNG better?

PNG for sharp text and UI, JPEG when file size matters.

Related

Updated 2026-12-01