Examples

Screenshot of a particular area with Python and Puppeteer

Heads up before you start

Puppeteer has no official Python port. The community port, pyppeteer, is no longer maintained and bundles an old Chromium. These examples still work, but for new projects we recommend Playwright for Python — it covers everything Puppeteer does and is actively maintained.

Install the Python Puppeteer port and Chromium

pip install pyppeteer
pyppeteer-install

Take a screenshot of the clip and save to file

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://www.htmltoimage.com/demo')
    await page.screenshot({'path': 'clip.png', 'clip': {'x': 0, 'y': 0, 'width': 480, 'height': 240}})
    await browser.close()

asyncio.run(main())

Find out how to take a full-page screenshot with Python and Puppeteer.

That was 11 lines of code — plus a browser to run in production

Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:

curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com"

Try the Urlbox screenshot API — free trial, no browser babysitting.