You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Python library performs remote control of any web browser that implements
the Chrome DevTools Protocol. It is built using the type wrappers in
python-chrome-devtools-protocol and implements
I/O using Trio. This library handles the
WebSocket negotiation and session management, allowing you to transparently
multiplex commands, responses, and events over a single connection.
The example below demonstrates the salient features of the library by navigating to a
web page and extracting the document title.
fromtrio_cdpimportopen_cdp, page, domasyncwithopen_cdp(cdp_url) asconn:
# Find the first available target (usually a browser tab).targets=awaittarget.get_targets()
target_id=targets[0].id# Create a new session with the chosen target.asyncwithconn.open_session(target_id) assession:
# Navigate to a website.asyncwithsession.page_enable()
asyncwithsession.wait_for(page.LoadEventFired):
awaitsession.execute(page.navigate(target_url))
# Extract the page title.root_node=awaitsession.execute(dom.get_document())
title_node_id=awaitsession.execute(dom.query_selector(root_node.node_id,
'title'))
html=awaitsession.execute(dom.get_outer_html(title_node_id))
print(html)
This example code is explained in the documentation
and more example code can be found in the examples/ directory of this repository.