Skip to main content

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

Project description

PyPI PyPI version Documentation Build Status codecov

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

WORK IN PROGRESS

Not all features are implemented or tested currently.

  • The following features are not implemented yet.

    • PDF screenshot

    • Page.waitForSelector() and Frame.waitForSelector()

    • Page.waitForFunction() and Frame.waitForFunction()

  • Free software: MIT license (including the work distributed under the Apache 2.0 license)

  • Documentation: https://miyakogi.github.io/pyppeteer

Installation

Pyppeteer requires python 3.6+.

pip install https://github.com/miyakogi/pyppeteer.git

Usage

Below code open web page and take a screenshot.

import asyncio
from pyppeteer.launcher import launch

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

browser = launch()
asyncio.get_event_loop().run_until_complete(main(browser))
browser.close()

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.

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 = page.querySelector('h1')
title = element.evaluate('(element) => element.innerText')

Credits

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyppeteer-0.0.4.tar.gz (35.4 kB view details)

Uploaded Source

File details

Details for the file pyppeteer-0.0.4.tar.gz.

File metadata

  • Download URL: pyppeteer-0.0.4.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyppeteer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4bba8e35a6199c6d448efc9c02f33623336ff5b93e54f70fdee588db9dd78146
MD5 7f79bccd39acd85909822bfae4f45df7
BLAKE2b-256 25f4847c023e62d0a0c4f0fba9d904b0d4384726f845281c652bebe2db239196

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page