AgentQL
The AgentQL module provides a method to launch an AgentQL Session for programmatic access to web interactions. The following is a typical example of using AgentQL to retrieve and interact with web elements:
- Sync
- Async
import agentql
session = agentql.start_session("https://www.google.com")
QUERY = """
{
search_box
search_btn
about_link
}
"""
aql_response_proxy = session.query(QUERY)
# More actions to interact with response
session.stop()
import agentql
session = await agentql.start_async_session("https://www.google.com")
QUERY = """
{
search_box
search_btn
about_link
}
"""
aql_response_proxy = await session.query(QUERY)
# More actions to interact with response
await session.stop()
Methods
start_session
Start a new synchronous AgentQL session with the given URL, web driver and user authentication session. By default, the session will use Playwright Web Driver.
Usage
session = agentql.start_session(URL)
agentql_response_proxy = session.query(QUERY)
print(agentql_response_proxy.to_data())
Arguments
url
str
URL to navigate session to. To navigate after a session has already started, users could start session with an initialized web driver and invoke driver.open_url()
method.
web_driver
WebDriver (optional)
The web driver to use. It is responsible for interacting with the browser and page. Defaults to Playwright web driver, which is built on top of the Playwright framework. Users could create their own synchronous or asynchronous web driver by implementing WebDriver
protocol in agentql.sync_api
module
user_auth_session
dict (optional)
The user authentication session that contains previous login session. Users could retrieve authentication session by starting a session, logging into desired website, and calling session.get_user_auth_session()
, which will return a auth_session
object defined in web driver.
enable_history_log
bool (optional)
Enables a history log to record all events during the session, which can be retrieved via session.get_last_trail()
.
Returns
An instance of AgentQL Session class.
start_async_session
Start a new asynchronous AgentQL session with the given URL, web driver and user authentication session. By default, session will use Playwright Web Driver.
Usage
session = agentql.start_async_session(URL)
agentql_response_proxy = await session.query(QUERY)
print(await agentql_response_proxy.to_data())
Arguments
url
str
URL to navigate session to. To navigate after a session has already started, users could start session with an initialized web driver and invoke driver.open_url()
method.
web_driver
WebDriver (optional)
The web driver to use. Web driver is responsible for interacting with the browser and page. Defaults to Playwright web driver, which is built on top of the Playwright framework. Users could create their own synchronous or asynchronous web driver by implementing WebDriver
protocol in agentql.async_api
module
user_auth_session
dict (optional)
The user authentication session that contains previous login session. Users could retrieve authentication session by starting a session, logging into desired website, and calling session.get_user_auth_session()
, which will return a auth_session
object defined in web driver.
enable_history_log
bool (optional)
Enable history log to record all the events during the session, retrieved via session.get_last_trail()
.
Returns
An instance of AgentQL Session class.