Skip to main content

Pyppeteer

PyPI PyPI version Documentation Build Status codecov

Unofficial Python port of puppeteer JavaScript (headless) chrome/chromium browser automation library.

WORK IN PROGRESS

Currently not all features are tested.

Installation

Pyppeteer requires python 3.6+.

Install by pip from PyPI:

pytyon3 -m pip install pyppeteer

Or install latest version from github:

python3 -m pip install -U git+https://github.com/miyakogi/pyppeteer.git@dev

Usage

Below code open web page and take a screenshot.

import asyncio
from pyppeteer.launcher import launch

async def main():
    browser = launch()
    page = await browser.newPage()
    await page.goto('http://example.com')
    await page.screenshot({'path': 'example.png'})
    browser.close()

asyncio.get_event_loop().run_until_complete(main())

Pyppeteer has almost same API as puppeteer. More APIs are listed in the document.

Puppeteer’s document is also useful for pyppeteer users.

Differences between puppeteer and pyppeteer

Pyppeteer is to be as similar as puppeteer, but some differences between python and JavaScript make it difficult.

These are differences between puppeteer and pyppeteer.

Keyword argument for options

Puppeteer uses object (dictionary in python) for passing options to functions/methods. Pyppeteer accepts both dictionary and keyword argument for options.

Dictionary style option (similar to puppeteer):

browser = launch({'headless': True})

Keyword argument style option (more pythonic, isn’t it?):

browser = launch(headless=True)

Element selector method name ($ -> querySelector)

In python, $ is not usable for method name. So pyppeteer uses Page.querySelector() instead of Page.$(), and ElementHandle.querySelector() instead of ElementHandle.$(). Pyppeteer has shorthand of this method, Page.J() and ElementHandle.J().

Argument of Page.evaluate() / ElementHandle.evaluate()

Puppeteer’s version of evaluate() takes JavaScript raw function, but pyppeteer takes string of JavaScript function.

Example to get element’s inner text:

element = await page.querySelector('h1')
title = await element.evaluate('(element) => element.textContent')

Credits

This package was created with Cookiecutter* and the audreyr/cookiecutter-pypackage* project template.

Release files for pyppeteer 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyppeteer 0.0.7
File Size Uploaded
pyppeteer-0.0.7.tar.gz 52.5 kB Details

Release files / pyppeteer-0.0.7.tar.gz

Download URL pyppeteer-0.0.7.tar.gz
Size 52.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9085c38fdff84664820bac7826e42502ea376fda26837b6fd901304b2239b7bd
BLAKE2b-256 checksum
How to use checksums
48696a7ed70fa0a13bc4d789df5e4b7482d9437fc6272f8287525e3d22cedd65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page