用于 Google Chrome 开发协议的 Python 包
项目描述
热铬
用于 Google Chrome 开发协议的 Python 包,更多文档
目录
安装
要安装 pychrome,只需:
$ pip install -U pychrome
或来自 GitHub:
$ pip install -U git+https://github.com/fate0/pychrome.git
或来自来源:
$ python setup.py install
设置 Chrome
简单地:
$ google-chrome --remote-debugging-port=9222
或无头模式(chrome 版本 >= 59):
$ google-chrome --headless --disable-gpu --remote-debugging-port=9222
或使用码头工人:
$ docker pull fate0/headless-chrome
$ docker run -it --rm --cap-add=SYS_ADMIN -p9222:9222 fate0/headless-chrome
入门
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)
或(替代语法)
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)
更多方法或事件可以在 Chrome DevTools 协议中找到
调试
设置调试环境变量:
标签管理
运行pychrome -h以获取更多信息
例子:
例子
请参阅示例目录以获取更多示例
发布
- 安装部门
pip install setuptools wheel twine - 包装
python setup.py sdist bdist_wheel - 上传
twine upload dist/*
参考
项目详情
关
cc12703_pychrome -0.2.6.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | e55929f869f03800bf26b5cb0d4a7ac526611c7b095e62104c400677a4dbe335 |
|
| MD5 | 1dae822c746f89989c2e9c628192cbc4 |
|
| 布莱克2-256 | dfa3de7b1f0293c7b68115e3b956d066f0a0dbb2093076f8310755c0b9bd8ee1 |
关
cc12703_pychrome -0.2.6-py2.py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | f0e8092d5dc9531268c5241b3747c7eb4932897c921367ddaae9fb03ca392cab |
|
| MD5 | 244b8f4f74513b6797e1542dda997796 |
|
| 布莱克2-256 | 8007db6df86e4ec0f5ca48866884e254fb9d859db3889babb3ac2c2511c618b0 |