Pyppeteer
this is my own temporary fork that bumps default chrome revision and handles newer chrome revisions correctly on windows
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_fork
Installation
Pyppeteer requires python 3.6+. (experimentally supports python 3.5)
Install by pip from PyPI:
python3 -m pip install pyppeteer_fork
Or install latest version from github:
python3 -m pip install -U git+https://github.com/miyakogi/pyppeteer_fork.git@dev
Usage
Note: When you run pyppeteer_fork first time, it downloads a recent version of Chromium (~100MB). If you don't prefer this behavior, run
pyppeteer_fork-installcommand before running scripts which uses pyppeteer_fork.
Example: open web page and take a screenshot.
import asyncio
from pyppeteer_fork 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_fork 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_fork users.
Differences between puppeteer and pyppeteer_fork
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_fork.
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_fork 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_fork 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_fork 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
- 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.
Metadata
Release files for pyppeteer-fork 0.0.28
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyppeteer_fork-0.0.28.tar.gz | 1.2 MB | Without provenance | Details for pyppeteer_fork-0.0.28.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyppeteer_fork-0.0.28-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pyppeteer_fork-0.0.28-py2.py3-none-any.whl |
Total release size: 1.3 MB
Release files / pyppeteer_fork-0.0.28.tar.gz
| Download URL | pyppeteer_fork-0.0.28.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a01bb91d7f73129c7263f99517d0c4beef67baeb77fa7b0a7bddf98cc109d5e8
|
|
BLAKE2b-256 checksum How to use checksums |
d01554de812eb4518e29d0601fad239be386a5730b9b439206f829f54988c645
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3
|
Release files / pyppeteer_fork-0.0.28-py2.py3-none-any.whl
| Download URL | pyppeteer_fork-0.0.28-py2.py3-none-any.whl |
|---|---|
| Size | 80.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1dd3a85bed996e4c981e5616df39ad4e648bda94586913b9c6ddefce26863795
|
|
BLAKE2b-256 checksum How to use checksums |
c910257a89fde61b29b9646c49cbda4cc6b14b156933f2a949cf780c4c01df13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3
|
Security for pyppeteer-fork 0.0.28
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.