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
Ref
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py3chrome-0.2.9.tar.gz
(10.9 kB
view details)
Built Distribution
File details
Details for the file py3chrome-0.2.9.tar.gz
.
File metadata
- Download URL: py3chrome-0.2.9.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e522f2444c4fe27b95d41e6bfe6e024aa76b501663918cfc949ea4a49d4396c0 |
|
MD5 | 8aaa1e9512bb369b436ea1b0dcddc65b |
|
BLAKE2b-256 | 9a0b4849975abab45626e699df661846575181bf83789526d0289ab22931acd9 |
File details
Details for the file py3chrome-0.2.9-py2.py3-none-any.whl
.
File metadata
- Download URL: py3chrome-0.2.9-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af0bde75a32b66a3546eb22c9f72200d4cd7383a48a3ed1110e4353aaa2160be |
|
MD5 | 8d0dc705cddec06f9d2864c59ca5afaf |
|
BLAKE2b-256 | 0a47d7975287c21f66bcdddfa7a39a64ab195435568062a883b2298b29eb352c |