Retour au classement

miyakogi/pyppeteer

Python

Headless chrome/chromium automation library (unofficial port of puppeteer)

headless-chromebrowser-automationpuppeteer
Croissance des étoiles
Étoiles
3.6k
Forks
369
Croissance hebdomadaire
Issues
133
1k2k3k
août 2017juil. 2020juil. 2023juil. 2026
ArtefactsPyPIpip install pyppeteer
README

Pyppeteer

Pyppeteer has moved to pyppeteer/pyppeteer


PyPI PyPI version Documentation Travis status AppVeyor status codecov

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

Installation

Pyppeteer requires python 3.6+. (experimentally supports python 3.5)

Install by pip from PyPI:

python3 -m pip install pyppeteer

Or install latest version from github:

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

Usage

Note: When you run pyppeteer first time, it downloads a recent version of Chromium (~100MB). If you don't prefer this behavior, run pyppeteer-install command before running scripts which uses pyppeteer.

Example: open web page and take a screenshot.

import asyncio
from pyppeteer import launch

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

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

Example: evaluate script on the page.

import asyncio
from pyppeteer import launch

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

    dimensions = await page.evaluate('''() => {
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight,
            deviceScaleFactor: window.devicePixelRatio,
        }
    }''')

    print(dimensions)
    # >>> {'width': 800, 'height': 600, 'deviceScaleFactor': 1}
    await 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 and troubleshooting are 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 arguments for options

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

Dictionary style option (similar to puppeteer):

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

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

browser = await launch(headless=True)

Element selector method name ($ -> querySelector)

In python, $ is not usable for method name. So pyppeteer uses Page.querySelector()/Page.querySelectorAll()/Page.xpath() instead of Page.$()/Page.$$()/Page.$x(). Pyppeteer also has shorthands for these methods, Page.J(), Page.JJ(), and Page.Jx().

Arguments of Page.evaluate() and Page.querySelectorEval()

Puppeteer's version of evaluate() takes JavaScript raw function or string of JavaScript expression, but pyppeteer takes string of JavaScript. JavaScript strings can be function or expression. Pyppeteer tries to automatically detect the string is function or expression, but sometimes it fails. If expression string is treated as function and error is raised, add force_expr=True option, which force pyppeteer to treat the string as expression.

Example to get page content:

content = await page.evaluate('document.body.textContent', force_expr=True)

Example to get element's inner text:

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

Future Plan

  1. Catch up development of puppeteer
    • Not intend to add original API which puppeteer does not have

Credits

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

Dépôts similaires
puppeteer/puppeteer

JavaScript API for Chrome and Firefox

TypeScriptnpmApache License 2.0headless-chrometesting
pptr.dev
95.3k9.5k
apify/crawlee

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

TypeScriptnpmApache License 2.0web-scrapingweb-crawling
crawlee.dev
24.8k1.6k
segment-boneyard/nightmare

A high-level browser automation library.

JavaScriptnpmelectronheadless-chrome
open.segment.com
19.8k1.1k
schickling/chromeless

🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.

TypeScriptnpmMIT Licenseserverlessintegration-testing
chromeless.netlify.com
13.2k569
pinchtab/pinchtab

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

GoGo ModulesMIT Licensebrowser-automationcdp
9.4k702
apify/crawlee-python

Crawlee—A web scraping and browser automation library for Python to build reliable crawlers. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Parsel, BeautifulSoup, Playwright, and raw HTTP. Both headful and headless mode. With proxy rotation.

PythonPyPIApache License 2.0apifyautomation
crawlee.dev/python/
9.3k778
berstend/puppeteer-extra

💯 Teach puppeteer new tricks through plugins.

JavaScriptnpmMIT Licensepuppeteerchrome
extra.community
7.4k780
alvarcarto/url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.

HTMLMIT Licensepdfchrome
7.1k778
GoogleChrome/rendertron

A Headless Chrome rendering solution

TypeScriptnpmApache License 2.0renderingheadless-chrome
render-tron.appspot.com
6k901
yujiosaka/headless-chrome-crawler

Distributed crawler powered by Headless Chrome

JavaScriptnpmMIT Licenseheadless-chromepuppeteer
5.6k404
getgauge/taiko

A node.js library for testing modern web applications

JavaScriptnpmMIT Licensetesting-toolsheadless
taiko.dev
3.7k460
thomasdondorf/puppeteer-cluster

Puppeteer Pool, run a cluster of instances in parallel

TypeScriptnpmMIT Licensepuppeteerpool
3.5k318