Skip to main content

pychrome

Build Status Codecov Updates PyPI PyPI

A Python Package for the Google Chrome Dev Protocol, more document

Table of Contents

Installation

To install pychrome, simply:

$ pip install -U pychrome

or from GitHub:

$ pip install -U git+https://github.com/fate0/pychrome.git

or from source:

$ python setup.py install

Setup Chrome

simply:

$ google-chrome --remote-debugging-port=9222

or headless mode (chrome version >= 59):

$ google-chrome --headless --disable-gpu --remote-debugging-port=9222

or use docker:

$ docker pull fate0/headless-chrome
$ docker run -it --rm --cap-add=SYS_ADMIN -p9222:9222 fate0/headless-chrome

Getting Started

import pychrome

# create a browser instance
browser = pychrome.Browser(url="http://127.0.0.1:9222")

# create a tab
tab = browser.new_tab()

# register callback if you want
def request_will_be_sent(**kwargs):
    print("loading: %s" % kwargs.get('request').get('url'))

tab.Network.requestWillBeSent = request_will_be_sent

# start the tab 
tab.start()

# call method
tab.Network.enable()
# call method with timeout
tab.Page.navigate(url="https://github.com/fate0/pychrome", _timeout=5)

# wait for loading
tab.wait(5)

# stop the tab (stop handle events and stop recv message from chrome)
tab.stop()

# close tab
browser.close_tab(tab)

or (alternate syntax)

import pychrome

browser = pychrome.Browser(url="http://127.0.0.1:9222")
tab = browser.new_tab()

def request_will_be_sent(**kwargs):
    print("loading: %s" % kwargs.get('request').get('url'))


tab.set_listener("Network.requestWillBeSent", request_will_be_sent)

tab.start()
tab.call_method("Network.enable")
tab.call_method("Page.navigate", url="https://github.com/fate0/pychrome", _timeout=5)

tab.wait(5)
tab.stop()

browser.close_tab(tab)

more methods or events could be found in Chrome DevTools Protocol

Debug

set DEBUG env variable:

pychrome_with_debug_env

Tab management

run pychrome -h for more info

example:

pychrome_tab_management

Examples

please see the examples directory for more examples

Ref

Release files for pychrome 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pychrome 0.2.4
File Size Uploaded
pychrome-0.2.4.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pychrome 0.2.4
File Interpreter ABI Platform
pychrome-0.2.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 19.9 kB

Release files / pychrome-0.2.4.tar.gz

Download URL pychrome-0.2.4.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
70392b6592e4d0a00e91324efd9c89f6e6e47fa31e7b38a69973dc6489453478
BLAKE2b-256 checksum
How to use checksums
775ee51089f733020ed96849f55803d46448ad1dc5fb1a5533013672dafdc90d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / pychrome-0.2.4-py2.py3-none-any.whl

Download URL pychrome-0.2.4-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5deeeaaf51609d8a3fb5e2961652981150c4eefb50e223848b0e7520c00e6366
BLAKE2b-256 checksum
How to use checksums
4a11b88e0b351b86350849e874a5d5dc52be3dd9a85dbe6c7aab40111ba2b49c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

1 release file

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page