How to use AgentQL?
To use AgentQL, follow these steps:
-
Installation:
- Install the AgentQL library:
pip install agentql
- Install Playwright dependencies:
playwright install
- Set your AgentQL API key as an environment variable:
AGENTQL_API_KEY
[2]
- Install the AgentQL library:
-
Import required libraries:
from agentql import wrap, configure from playwright.sync_api import sync_playwright
-
Configure AgentQL with your API key:
configure(api_key=your_api_key)
-
Launch a browser and navigate to a website:
with sync_playwright() as p: browser = p.chromium.launch() page = wrap(browser.new_page()) page.goto("https://example.com")
-
Define an AgentQL query to interact with elements:
QUERY = """ search_box """
-
Execute the query and interact with elements:
response = page.query_elements(QUERY) search_box = response.search_box search_box.fill("search term")
-
For data extraction, use the
query_data
method:data = page.query_data(QUERY)
AgentQL offers natural language selectors, making it intuitive to find elements based on their context and meaning rather than DOM structure[5]. It can be used for web scraping, automation, and testing across different websites[4].
Citations:
[1] https://docs.agentql.com/quick-start
[2] https://docs.agentql.com/python-sdk/installation
[3] https://docs.agentql.com/getting-started/first-steps
[4] https://github.com/tinyfish-io/agentql
[5] https://docs.agentql.com/concepts/query-language
[6] https://www.agentql.com/scraping/jetbrains-com
[7] https://docs.agentql.com/guides
[8] https://docs.agentql.com/concepts/under-the-hood