A Python Package for the Google Chrome Dev Protocol
Project description
pychrome
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:
Tab management
run pychrome -h
for more info
example:
Examples
please see the examples directory for more examples
Publish
- install deps
pip install setuptools wheel twine
- pacakge
python setup.py sdist bdist_wheel
- upload
twine upload dist/*
Ref
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cc12703_pychrome-0.2.6.tar.gz
(548.1 kB
view details)
Built Distribution
File details
Details for the file cc12703_pychrome-0.2.6.tar.gz
.
File metadata
- Download URL: cc12703_pychrome-0.2.6.tar.gz
- Upload date:
- Size: 548.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.10.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e55929f869f03800bf26b5cb0d4a7ac526611c7b095e62104c400677a4dbe335 |
|
MD5 | 1dae822c746f89989c2e9c628192cbc4 |
|
BLAKE2b-256 | dfa3de7b1f0293c7b68115e3b956d066f0a0dbb2093076f8310755c0b9bd8ee1 |
File details
Details for the file cc12703_pychrome-0.2.6-py2.py3-none-any.whl
.
File metadata
- Download URL: cc12703_pychrome-0.2.6-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.10.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e8092d5dc9531268c5241b3747c7eb4932897c921367ddaae9fb03ca392cab |
|
MD5 | 244b8f4f74513b6797e1542dda997796 |
|
BLAKE2b-256 | 8007db6df86e4ec0f5ca48866884e254fb9d859db3889babb3ac2c2511c618b0 |