Pyppeteer

2.0.0 · maintenance · verified Sat Apr 11

Pyppeteer is an unofficial Python port of Puppeteer, a Node.js library for controlling headless Chrome/Chromium. It provides a high-level API for browser automation tasks such as web scraping, automated testing, generating PDFs, and capturing screenshots, leveraging Python's asyncio for asynchronous operations. The current stable version is 2.0.0, though the project is considered to be in a maintenance phase with infrequent updates.

Warnings

Install

Imports

Quickstart

This quickstart launches a headless Chromium browser, opens a new page, navigates to 'https://example.com', prints the page title, takes a screenshot saved as 'example.png', and then closes the browser. It uses Python's `asyncio` for asynchronous execution.

import asyncio
from pyppeteer import launch
import os

async def main():
    # Launch the browser in headless mode by default
    # Set headless=False to see the browser UI
    browser = await launch(headless=True)
    page = await browser.newPage()
    await page.goto('https://example.com')
    print(f"Page title: {await page.title()}")
    await page.screenshot({'path': 'example.png'})
    await browser.close()

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →