跳转到主要内容

用于Chrome DevTools Protocol (CDP)的Trio驱动程序

项目描述

Trio CDP

PyPI Python Versions MIT License Build Status Read the Docs

此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/目录中找到。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

trio-chrome-devtools-protocol-0.6.0.tar.gz (57.1 kB 查看哈希值)

上传于

构建分发

trio_chrome_devtools_protocol-0.6.0-py3-none-any.whl (79.6 kB 查看哈希值)

上传于 Python 3

由以下支持