AgentQL
The agentql
module provides utility methods to convert Playwright's Page
to AgentQL's Page
, which gives access to AgentQL's querying API.
The following example creates a page, navigates it to a URL, and queries for web elements:
python
import agentql from playwright.sync_api import sync_playwright QUERY = """ { search_box search_btn } """ with sync_playwright() as p, p.chromium.launch(headless=False) as browser: page = agentql.wrap(browser.new_page()) # Wraps the Playwright Page to access AgentQL's features. # page.goto("https://duckduckgo.com") aql_response = page.query_elements(QUERY) aql_response.search_box.type("AgentQL") aql_response.search_btn.click() # Used only for demo purposes. It allows you to see the effect of the script. page.wait_for_timeout(10000)
Methods
wrap
Casts a Playwright Sync Page
object to an AgentQL Page
type to get access to AgentQL's querying API. See AgentQL Page
reference for API details.
Usage
python
page = agentql.wrap(browser.new_page())
Arguments
page
Playwright's Page
Returns
wrap_async
Casts a Playwright Async Page
object to an AgentQL Page
type to get access to the AgentQL's querying API. See AgentQL Page
reference for API details.
Usage
python
page = agentql.wrap_async(browser.new_page())
Arguments
page
Playwright's Page