Package: pyppeteer-fork
Pyppeteerthis is my own temporary fork that bumps default chrome revision
and handles newer chrome revisions correctly on windowsUnofficial Python port ofpuppeteerJavaScript (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_forkInstallationPyppeteer requires python 3.6+.
(experimentally supports python 3.5)Install by pip from PyPI:python3 -m pip install pyppeteer_forkOr install latest version fromgithub:python3 -m pip install -U git+https://github.com/miyakogi/pyppeteer_fork.git@devUsageNote: When you run pyppeteer_fork first time, it downloads a recent version of Chromium (~100MB).
If you don't prefer this behavior, runpyppeteer_fork-installcommand before running scripts which uses pyppeteer_fork.Example: open web page and take a screenshot.importasynciofrompyppeteer_forkimportlaunchasyncdefmain():browser=awaitlaunch()page=awaitbrowser.newPage()awaitpage.goto('http://example.com')awaitpage.screenshot({'path':'example.png'})awaitbrowser.close()asyncio.get_event_loop().run_until_complete(main())Example: evaluate script on the page.importasynciofrompyppeteer_forkimportlaunchasyncdefmain():browser=awaitlaunch()page=awaitbrowser.newPage()awaitpage.goto('http://example.com')awaitpage.screenshot({'path':'example.png'})dimensions=awaitpage.evaluate('''() => {return {width: document.documentElement.clientWidth,height: document.documentElement.clientHeight,deviceScaleFactor: window.devicePixelRatio,}}''')print(dimensions)# >>> {'width': 800, 'height': 600, 'deviceScaleFactor': 1}awaitbrowser.close()asyncio.get_event_loop().run_until_complete(main())Pyppeteer has almost same API as puppeteer.
More APIs are listed in thedocument.Puppeteer's documentandtroubleshootingare also useful for pyppeteer_fork users.Differences between puppeteer and pyppeteer_forkPyppeteer 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 optionsPuppeteer 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=awaitlaunch({'headless':True})Keyword argument style option (more pythonic, isn't it?):browser=awaitlaunch(headless=True)Element selector method name ($->querySelector)In python,$is not usable for method name.
So pyppeteer_fork usesPage.querySelector()/Page.querySelectorAll()/Page.xpath()instead ofPage.$()/Page.$$()/Page.$x(). Pyppeteer also has shorthands for these
methods,Page.J(),Page.JJ(), andPage.Jx().Arguments ofPage.evaluate()andPage.querySelectorEval()Puppeteer's version ofevaluate()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, addforce_expr=Trueoption,
which force pyppeteer_fork to treat the string as expression.Example to get page content:content=awaitpage.evaluate('document.body.textContent',force_expr=True)Example to get element's inner text:element=awaitpage.querySelector('h1')title=awaitpage.evaluate('(element) => element.textContent',element)Future PlanCatch up development of puppeteerNot intend to add original API which puppeteer does not haveCreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.