The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For a direct, self-hosted Python workflow, use Playwright: launch a browser, navigate to the page, and call page.screenshot(). It can save a viewport image or full page, capture a specific element, or return image bytes for further processing. If you want a hosted API instead of running a browser, ScreenshotNeo offers a one-request option.
Capture a website screenshot with Python and Playwright
Playwright is a browser-automation library, so it renders the target website in a real browser before capturing it. Install the Python package and the browser engine you plan to use, then navigate to a URL and save the screenshot. The example below uses Chromium and the synchronous API.
from playwright.sync_api import sync_playwright
url = "https://example.com"
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page(viewport={"width": 1440, "height": 900})
page.goto(url, wait_until="load", timeout=60_000)
page.screenshot(path="screenshot.png")
browser.close()
The image captures the visible viewport at the configured dimensions. The basic screenshot call is page.screenshot(path="screenshot.png"). Playwright documents this browser lifecycle and screenshot flow in its Python Screenshots guide and Python Page API.
Install the package and browser
In a fresh Python environment, install Playwright and then install the browser binaries. The Playwright installation guide provides the current commands for your operating system and environment; follow its Python instructions before running the example. A Python package install alone does not guarantee a browser is present to launch.
#1 Best Overall
Choose synchronous or asynchronous Python
The synchronous API is convenient for scripts and simple jobs. Playwright also documents an asynchronous API, which can fit applications already built around asyncio. Do not mix the synchronous and asynchronous interfaces in the same flow; use the matching import and await calls throughout.
import asyncio
from playwright.async_api import async_playwright
async def capture(url: str) -> None:
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page(viewport={"width": 1440, "height": 900})
await page.goto(url, wait_until="load", timeout=60_000)
await page.screenshot(path="screenshot.png")
await browser.close()
asyncio.run(capture("https://example.com"))
Choose viewport, full-page, element, or bytes
The screenshot call changes depending on what the output needs to show. A viewport capture records the current browser view; a full-page capture extends to the page’s scrollable height; a locator capture targets an element; and omitting the output path returns bytes instead of writing a file.
| Capture goal | Playwright call | What to expect |
|---|---|---|
| Visible browser view | page.screenshot(path="view.png") |
Captures the current viewport. |
| Whole scrollable page | page.screenshot(path="full.png", full_page=True) |
Captures as if the page fit on a very tall screen. |
| One element | page.locator(".header").screenshot(path="header.png") |
Captures the selected element’s bounds; Playwright scrolls it into view. |
| Image bytes | image = page.screenshot() |
Returns bytes that can be passed to another function or saved by your code. |
For a full page, add full_page=True. For one element, use a locator and its screenshot() method. Element captures can be affected by overlays, a locator becoming detached during capture, or content inside a scrollable element. See the screenshots guide and Locator API for documented behavior and options.
Use bytes when a file is not the final destination
Without path, page.screenshot() returns image bytes. That is useful when a later step uploads the image, stores it in an object store, or processes it in memory. The capture still consumes browser resources; returning bytes only changes how your Python code receives the result.
Rank #2
Set output format and screenshot options
Playwright’s documented screenshot formats are PNG, JPEG, and WebP. Set type to choose a format, and use quality for lossy formats such as JPEG or WebP. Other options control pixel scaling, transparency, masking, animations, CSS, and timeouts. Consult the Page API for exact accepted values and defaults for the version you install.
- Format: PNG is lossless; JPEG and WebP are lossy options. Choose based on downstream compatibility, file size, and visual fidelity.
- Scale: CSS-pixel and device-pixel scaling affect the output dimensions and detail. Keep viewport and scale consistent when comparing captures.
- Transparency: Background transparency is available for supported output configurations; it can be useful for component images, but check the format requirements in the API documentation.
- Masking: Mask locators to cover regions that contain variable or sensitive visual content.
- Animation and styles: Animation controls and stylesheet overrides can reduce visual movement or hide elements. They do not make a changing site deterministic by themselves.
- Timeouts: Screenshot operations have timeout controls. A timeout for capture is distinct from the timeout used while navigating to the URL.
Wait for the page state your capture needs
page.goto() supports navigation wait conditions, but no single condition is right for every site. The example uses wait_until="load" as a straightforward starting point. A page can continue changing after its load event: a client-side app may fetch data, images may load lazily, and animations or rotating content may continue while the browser is open.
For repeatable captures, decide what “ready” means for the page. If a particular element indicates that the useful content is rendered, wait for that locator before capturing. For pages with delayed content, use a task-specific wait rather than assuming that a fixed delay or one navigation event always signals readiness. The Playwright API documents navigation and locator-wait methods; select one that matches the site and capture goal.
- Set a consistent viewport and device scale for the task.
- Navigate using a suitable wait condition and navigation timeout.
- Wait for a meaningful page-specific signal when content is rendered dynamically.
- Capture the viewport, full page, or target locator only after that condition is met.
Even with these controls, changing page content can produce different images across runs. When comparing results, record the browser engine, viewport, scale, output format, and how animation or variable content is handled.
Run captures responsibly and keep browser costs predictable
A screenshot job uses a browser process, a page, and the resources needed to load the destination. Close the browser after capture, as in the examples, and reuse a browser within a controlled batch where that suits your application rather than launching one for every URL. Keep timeouts bounded so a stalled destination does not hold a worker indefinitely.
For batch or server use, also consider concurrency and the memory required by full-page captures. Very tall pages and large device-pixel output can create larger image files and increase processing demands. The documentation establishes the capture options, but does not provide universal speed, memory, or reliability figures; measure the workload in your own deployment before setting concurrency limits.
Playwright or Selenium for Python screenshots?
Selenium is another browser-automation route, and its WebDriver documentation includes screenshot support. The available documentation supports recognizing it as an alternative, but not declaring a universal winner or comparing performance. Choose based on your existing project stack, session setup, browser interactions, desired capture scope, and the output controls your task requires.
Recommended Free Tools
For Playwright, the documented calls cover viewport, full-page, and locator screenshots as well as returned bytes and image options. If a project already uses Selenium, using its existing browser setup may be more practical than adding another framework. See the Selenium WebDriver interactions documentation for its screenshot capability.
Or skip the browser setup
If you do not want to install and manage a browser, ScreenshotNeo is a hosted website screenshot API and MCP server. A GET request can return a PNG, JPEG, WebP, or PDF. This cURL example saves a WebP screenshot of the requested URL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request details. Cookie banners are accepted as a visitor and removed, along with supported newsletter popups and chat widgets, before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server gives AI agents tools for taking screenshots, getting page information, and capturing PDFs. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Troubleshooting common capture failures
The browser does not launch
The Python package may be installed while the browser executable is not. Install the browser binaries using Playwright’s installation instructions for your environment, then retry. In a managed or containerized deployment, verify that the selected browser is available and that the runtime permits it to launch.
The screenshot is blank or missing dynamic content
The capture may have happened before the page finished rendering the content you need. Check the navigation result and choose a page-specific readiness signal, such as a locator becoming visible, before taking the screenshot. A load event alone may not represent completion for a client-rendered page.
Best Value
The navigation times out
A destination may be slow, unreachable, or waiting on resources that never complete. Confirm the URL and network access from the environment running Python, then choose a navigation wait condition appropriate to the page and set a bounded timeout. Do not assume increasing the timeout will fix a page that cannot be reached.
An element screenshot fails or includes unexpected content
Check that the locator matches the intended element and remains attached until capture. Playwright scrolls the element into view, but overlays and the element’s own scrolling behavior can affect the result. If the page changes during capture, wait for it to stabilize or use a locator that more precisely identifies the target.
The image is too large or differs between runs
Check the viewport, device scale, capture mode, and format. A full-page capture or device-pixel scaling can increase dimensions substantially. Dynamic content and animation can also vary between runs; use documented animation or stylesheet controls where appropriate and record the settings used.
Frequently asked questions
Can Playwright capture a page that requires a login?
The screenshot APIs operate on a browser page, so the page must reach the desired state before capture. The cited screenshot documentation does not establish a specific authentication recipe; use the browser session and project-specific login flow appropriate to the site, and follow its access rules.
Can I use Firefox or WebKit instead of Chromium?
Yes. The documented Playwright flow supports launching Chromium, Firefox, or WebKit. Install the required browser and select its corresponding Playwright launcher.
Does a full-page screenshot include content that only appears after scrolling?
Full-page mode captures the scrollable page in a tall-page layout. Content loaded only as a result of scrolling may still need to be triggered before capture; wait for the relevant content to load when that matters.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

