A Python Package for the Google Chrome Dev Protocol [threading base]
Clone or download
fate0 Merge pull request #21 from geekscrapy/master
Added queue.task_done()
Latest commit 3265932 Apr 14, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs update docs Aug 27, 2017
examples add examples Sep 19, 2017
pychrome Added queue.task_done() Apr 14, 2018
tests remove useless code Aug 31, 2017
.coveragerc update exclude lines Aug 27, 2017
.gitignore add site Aug 15, 2017
.travis.yml add no-sandbox Mar 8, 2018
LICENSE release 0.1.0 Aug 2, 2017
MANIFEST.in release 0.1.0 Aug 2, 2017
README.md update README.md Aug 31, 2017
mkdocs.yml update docs Aug 27, 2017
requirements_dev.txt fix build error Aug 27, 2017
setup.cfg release 0.1.0 Aug 2, 2017
setup.py switch back to threading base Aug 31, 2017
tox.ini remove python3.3 Aug 27, 2017

README.md

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