What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert a live webpage or supplied HTML into an image in Python, use Playwright when you need a real browser to render the page, and use WeasyPrint when its HTML/CSS rendering behavior fits your document. Playwright can save a viewport, a full-page image, or a selected element as PNG, JPEG, or WebP. The right choice depends on whether the page needs browser layout and interaction, what part you need to capture, and how you handle external assets.

Choose the right Python approach

HTML is a description of content and layout, not an image file. A renderer must first interpret it, load any resources, and lay it out before the result can be rasterized. For a webpage or markup that relies on browser behavior, Playwright drives a browser and takes a screenshot. WeasyPrint is an alternative HTML rendering library; its API accepts HTML sources and a base URL for resolving relative resources.

Need Better starting point Why
Capture a live website using browser layout Playwright It drives Chromium, Firefox, or WebKit and exposes page and element screenshot methods. Playwright screenshot guide; browser installation guide.
Capture a specific element or the whole scrollable page Playwright Use a locator screenshot for an element or full_page=True for full-page capture. Screenshot guide; Page API.
Render HTML input with relative files or URLs WeasyPrint Its HTML API accepts several input forms and a base_url for resolving relative resources. WeasyPrint API reference.
Render content that depends on JavaScript or browser interaction Playwright is the documented browser-driven option here The available WeasyPrint documentation does not establish parity with an interactive browser for JavaScript-driven pages.

For a simple, reproducible screenshot of a webpage or supplied HTML, the examples below use Playwright. The WeasyPrint section explains when to consider the alternative.

Install Playwright and its browser

Install the Python package, then install browser binaries. The browser installation is a separate setup step; installing only the package does not complete the documented setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. Install the package: python -m pip install playwright.
  2. Install browser binaries: python -m playwright install.
  3. Save one of the scripts below as a Python file and run it with the same Python environment where Playwright was installed.

Playwright documents both synchronous and asynchronous Python APIs and Chromium, Firefox, and WebKit browser engines. The examples use the synchronous API and Chromium for brevity. See the Playwright Python guide and browser installation guide for setup details and engine options.

Capture a webpage as an image

Save the full scrollable page as PNG

This script opens a URL and writes a PNG containing the full page, rather than just the initially visible viewport:

from playwright.sync_api import sync_playwright

url = "https://example.com"

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto(url)
    page.screenshot(path="page.png", full_page=True)
    browser.close()

Replace the example URL with the page you intend to capture. page.goto navigates the browser to that address; page.screenshot writes the image to the path given. The documented full-page option captures the page’s full scrollable area. For a viewport-only image, omit full_page=True. See the screenshot guide and Page API.

Set a viewport deliberately

The viewport affects line wrapping and layout, so set it to match the intended output rather than relying on an implicit default. For example, create the page with a specified viewport:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
page = browser.new_page(viewport={"width": 1440, "height": 900})

This sets the browser viewport dimensions in CSS pixels. A viewport screenshot is limited to that visible area; adding full_page=True expands the capture to the full scrollable page. Playwright’s screenshot API also supports device scale and clip-area options; check the Page API for their precise behavior and available parameters.

Capture one element

When you need a card, chart, or other specific region rather than the entire page, locate the element and call its screenshot method:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    page.locator("main").screenshot(path="main.png")
    browser.close()

Replace main with a CSS selector that identifies the target on your page. The locator screenshot captures that element; if the selector matches nothing, the capture cannot proceed. See the screenshot guide for element screenshots.

Render supplied HTML instead of a URL

For markup you already have in Python, set the browser page content and then capture it. This example writes a small HTML document and saves its rendered page as an image:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
from playwright.sync_api import sync_playwright

html = """
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <style>
      body { font: 18px sans-serif; margin: 32px; }
      .card { padding: 24px; background: #f2f4f7; border-radius: 12px; }
    </style>
  </head>
  <body>
    <div class="card">Rendered from Python HTML.</div>
  </body>
</html>
"""

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 900, "height": 500})
    page.set_content(html)
    page.screenshot(path="html.png", full_page=True)
    browser.close()

Use page.set_content for markup in memory; use page.goto for a live page. Relative links and image URLs in supplied markup need a usable base or absolute URLs if they are to resolve correctly. For more control over input and page behavior, consult the Page API.

Choose format, scope, and image quality

Playwright’s Page API documents PNG, JPEG, and WebP screenshots. PNG is the straightforward choice for lossless output. JPEG and WebP accept quality controls; PNG does not. Choose the format and scope according to how the image will be used rather than changing formats after capture.

  • PNG: suitable when you want the documented lossless screenshot output and do not need a quality setting.
  • JPEG or WebP: use when those formats suit the consuming application; set quality where appropriate. The API documents quality controls for these formats.
  • Viewport: captures the visible browser area and is useful when a fixed screen-sized image is the goal.
  • Full page: use full_page=True to include the scrollable page.
  • Element: use a locator screenshot when only one component is needed.

Capture bytes in memory by omitting the output path. This is useful if another Python step will process or store the image:

image_bytes = page.screenshot(full_page=True)

The Page API returns screenshot bytes when no path is provided. Keep in mind that the in-memory result still occupies memory until released or passed onward. For more screenshot parameters, including format and clip area, see the Page API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Consider WeasyPrint for suitable HTML documents

WeasyPrint provides a Python HTML API. It accepts sources such as filenames, URLs, or file objects, and its base_url argument helps resolve relative resources such as image URLs. Consider it when your document fits its supported rendering behavior and output requirements. The available documentation does not establish that it reproduces arbitrary JavaScript-heavy interactive pages like a full browser, so check your specific document before choosing it for such work.

WeasyPrint’s output is a PDF-oriented rendering workflow in the documented API; if your required final artifact is a raster image, confirm the appropriate conversion path for your deployment. Do not assume that an HTML-to-PDF renderer alone produces a PNG. Review the WeasyPrint API reference for current HTML input and base URL behavior.

Security when HTML is untrusted

WeasyPrint warns that untrusted HTML or CSS may introduce security problems. Treat user-supplied markup as untrusted input: assess the risk before rendering it, and do not expose a rendering process or its environment to resources or files that the input should not access. The warning is documented in the WeasyPrint documentation.

Common problems and fixes

  • Playwright cannot find a browser executable: the Python package may be installed without its browser binaries. Run python -m playwright install in the intended environment, as described in the browser installation guide.
  • The output shows only the first screen: a default screenshot covers the viewport. Add full_page=True to capture the scrollable page, or use a locator screenshot for a specific element.
  • The page is laid out at unexpected dimensions: set the viewport explicitly when creating the page. The viewport controls browser layout and thus can affect wrapping and element positions.
  • An element screenshot fails to find its target: check that the CSS selector matches an element on the loaded page. A locator screenshot requires a target element.
  • Images or styles referenced by supplied HTML are missing: relative resources need a resolvable base. Use absolute resource URLs or a rendering approach with a configured base URL; WeasyPrint documents base_url for this purpose.
  • A JavaScript-driven page is incomplete: allow the page’s relevant content to load before capturing and use a browser-driven workflow. The provided documentation supports browser screenshots but does not prescribe a single wait strategy for every website; select and verify a wait condition appropriate to the page.
  • WeasyPrint rendering differs from an interactive browser: the available documentation does not establish browser parity for JavaScript-heavy pages. Test the actual document and prefer browser automation when its behavior is required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

Playwright setup includes browser binaries in addition to the Python package, which affects installation and deployment. The supplied documentation does not establish comparative speed, memory consumption, or benchmark results for these approaches, so test your own pages and runtime rather than relying on a general performance claim. Reuse a browser process thoughtfully when capturing multiple pages in one run, and close it after the work to release browser resources.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For reliable output, decide in advance whether the deliverable is viewport-sized, full-page, or element-only; fix the viewport where layout matters; and confirm that the resources needed by the page can load in the execution environment. A screenshot can be syntactically successful while still reflecting a blank, partial, or unexpected page if navigation or rendering did not produce the intended content. Validate representative outputs in your application.

Or skip the browser setup

If your goal is to get a website screenshot from Python without installing and operating browser binaries, ScreenshotNeo offers a screenshot API. It accepts a URL in one GET request and can return PNG, JPEG, WebP, or PDF. See ScreenshotNeo and its API documentation.

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is on every plan.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month without a card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently asked questions

Can I capture a page without saving an image file first?

Yes. Playwright returns screenshot bytes when you call page.screenshot() without a path, so you can pass the result to downstream Python code.

Can Playwright use a browser other than Chromium?

Yes. Playwright’s Python documentation lists Chromium, Firefox, and WebKit browser engines. Install and launch the engine you need using the documented browser setup.

Does WeasyPrint render arbitrary JavaScript-based websites like a browser?

The available WeasyPrint documentation does not establish that. For pages whose output depends on browser interaction or JavaScript, use a browser-driven approach or verify the specific page’s output before relying on it.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.