Unofficial Python port of puppeteer JavaScript (headless) chrome/chromium browser automation library.
Free software: MIT license (including the work distributed under the Apache 2.0 license)
Documentation: https://miyakogi.github.io/pyppeteer
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
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.textContent')
Credits
This package was created with Cookiecutter* and the audreyr/cookiecutter-pypackage* project template.
Release files for pyppeteer 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyppeteer-0.0.5.tar.gz | 36.1 kB | Details |
Release files / pyppeteer-0.0.5.tar.gz
| Download URL | pyppeteer-0.0.5.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5cc973d322f9ac472bec158000cf03a1697a4cebb37db8dfb413fc45f37713f
|
|
BLAKE2b-256 checksum How to use checksums |
26eaa7fcb44542c8cbd34f447b30cec8ff59c3f1d1c1477215282be2c44c2c99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |