用于Chrome DevTools Protocol (CDP)的Trio驱动程序
项目描述
Trio CDP
此Python库可以远程控制实现Chrome DevTools Protocol的任何网络浏览器。它是使用python-chrome-devtools-protocol中的类型包装构建的,并使用Trio实现I/O。此库处理WebSocket协商和会话管理,允许您在单个连接上透明地多路复用命令、响应和事件。
以下示例通过导航到网页并提取文档标题来展示库的主要功能。
from trio_cdp import open_cdp, page, dom
async with open_cdp(cdp_url) as conn:
# Find the first available target (usually a browser tab).
targets = await target.get_targets()
target_id = targets[0].id
# Create a new session with the chosen target.
async with conn.open_session(target_id) as session:
# Navigate to a website.
async with session.page_enable()
async with session.wait_for(page.LoadEventFired):
await session.execute(page.navigate(target_url))
# Extract the page title.
root_node = await session.execute(dom.get_document())
title_node_id = await session.execute(dom.query_selector(root_node.node_id,
'title'))
html = await session.execute(dom.get_outer_html(title_node_id))
print(html)
此示例代码在文档中进行了解释,更多示例代码可以在此存储库的examples/
目录中找到。
项目详情
关闭
哈希值 for trio_chrome_devtools_protocol-0.6.0-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 03082a22060946bc099c1065ae476bc72ef96545d5041e3d341c02b43f886e4f |
|
MD5 | cddacb3038644706a0c77cfc5c48fba9 |
|
BLAKE2b-256 | bef0de591fa5c05a7e1d112653712deb4d5ba99cd58a8b9cc550c50f358b5909 |