AgentQL Documentation
website·Indexed 34 days ago
https://docs.agentql.comAn AI-powered query language and parser that uses natural language selectors for web scraping and automation. It provides Python and JavaScript SDKs, a Chrome Debugger Extension, and a REST API to extract structured data and interact with web elements. Features include integration with Playwright, remote browser allocation, bot detection avoidance, and compatibility with Google's Agent Development Kit (ADK).
What's inside AgentQL
- Websites use anti-bot systems that analyze request speed, user agents, and IP addresses to block automated access. To bypass these systems, developers should implement techniques that make the bot's behavior mimic a human user. Key strategies include using proxies, rotating headers, enabling stealth mode for headless browsers, and simulating user-like behavior.
Overview of AgentQL JavaScript SDK core modules
The AgentQL JavaScript SDK provides a set of modules and classes to automate web interactions and extract data at scale. Key components include:
agentqlmodule: Used for global configurations (such as setting the API key) and converting standard Playwright Page objects into AgentQL Page objects.agentql/toolsmodule: Provides utilities for data extraction, web automation, and remote browser session management.AgentQL Page: A wrapper around the Playwright Page class that enables the use of AgentQL's querying API.AQLResponseProxy: A metadata structure returned by thequeryElements()method on an AgentQL Page, allowing developers to access web elements using intuitive dot notation rather than raw data.
Overview of AgentQL Python SDK core components
The AgentQL Python SDK provides a suite of tools to automate web interactions and extract data. Key components include:
agentqlmodule: Contains utility methods to convert a standard Playwright Page into an AgentQL Page.AgentQL Page: A wrapper around Playwright's Page that enables the use of AgentQL's querying API.agentql.toolsmodule: Provides utility methods specifically for web automation and data extraction.PaginationInfo: A class used to manage pagination and navigate to subsequent pages.
Overview of AgentQL's core functionality
AgentQL is a query language that allows users to interact with web elements and extract data using natural language queries. It processes web pages by combining the structural layout of the HTML with the semantic information from the page's accessibility tree to accurately identify elements and content.Overview of AgentQL Core Components
AgentQL is an AI-powered toolset for retrieving web elements and data using natural language queries instead of traditional DOM, XPath, or CSS selectors. It consists of three main components:
- AgentQL Query Language: A natural language-like syntax used to describe and locate web elements and data, making scripts resilient to website structure changes.
- AgentQL SDKs (Python and JavaScript): Libraries used to integrate queries into automation scripts, scrapers, and testing frameworks (with first-class support for Playwright).
- AgentQL Debugger: A Chrome Extension for real-time interactive testing and visualization of queries on live webpages before integrating them into code.
Deploy AgentQL scripts to cloud services
To deploy an AgentQL script, build the Docker image, push it to a registry (e.g., Docker Hub or AWS ECR), and run it on a cloud service (e.g., AWS EC2).
Key Considerations:
- CPU Architecture: Ensure the Docker image architecture (e.g.,
arm64) matches the cloud service instance architecture. - Environment Variables: Set
AGENTQL_API_KEYin the cloud service environment. - Resource Monitoring: Playwright browser instances are resource-intensive; monitor CPU and memory and scale the instance size if necessary.
- CPU Architecture: Ensure the Docker image architecture (e.g.,
Interact with web elements using AQLResponseProxy
The
AQLResponseProxyclass is returned by thepage.queryElements()method. It acts as a metadata structure that allows developers to access web elements using dot notation based on the names defined in their AQL queries.When accessing a leaf node (an innermost element) in the query, the proxy returns a Playwright Locator, allowing direct interaction via the Playwright Locator API (e.g.,
.click(),.type()). For container nodes, it returns anotherAQLResponseProxyobject to allow further chaining.const { configure, wrap } = require('agentql'); const { chromium } = require('playwright'); const QUERY = ` { search_box header { search_btn } } `; (async () => { configure({ apiKey: process.env.AGENTQL_API_KEY }); const browser = await chromium.launch({ headless: false }); const page = await wrap(await browser.newPage()); await page.goto('https://duckduckgo.com'); // Get AQLResponseProxy const aqlResponse = await page.queryElements(QUERY); // Access elements with dot notation as Playwright Locators await aqlResponse.search_box.type('AgentQL'); await aqlResponse.header.search_btn.click(); await browser.close(); })();Select the appropriate AgentQL tool for query development
AgentQL provides several tools to help developers test, debug, and optimize queries for web data extraction:
- AgentQL Playground: A browser-based environment for quickly creating and testing queries without local setup.
- AgentQL Debugger: A browser extension used to optimize queries in real-time directly on any live web page.
- AgentQL CLI: A command-line interface for interacting with AgentQL SDKs.
- Tetra: A tool for executing AgentQL queries on remotely hosted Chromium instances.
Add context to AgentQL queries for higher precision
AgentQL allows you to specify additional details about the data you want to extract by adding context in parentheses()immediately after a term. This is used to refine results, exclude specific items, or disambiguate between similar elements on a page using plain English.{ products(exclude sponsored results)[] }AgentQL Query Language Overview
AgentQL is an AI-powered parser that replaces traditional CSS/XPath selectors with semantic, natural language queries.
Key capabilities include:
- Self-healing: Queries adapt to UI changes, A/B tests, and redesigns without requiring manual updates.
- Cross-site Compatibility: A single query can often work across multiple different websites that share similar data structures (e.g., different real estate sites).
- Controlled Output: The query defines the exact JSON structure of the returned data, eliminating the need for post-processing.
- Deterministic Results: Provides consistent output for the same input, suitable for automated testing and data pipelines.
Schedule scraping jobs via AgentQL Dev Portal
AgentQL's Dev Portal allows users to schedule multiple scraping workflows across different websites using AgentQL queries. This feature is currently experimental and subject to the following limitations per user: 2 workflows, 5 URLs per workflow, and 10 runs per workflow.Understand Playwright actionability checks
Playwright automatically performs actionability checks before actions like clicking, hovering, or typing to prevent timeout errors and ensure reliability. An element is considered actionable only if it meets the following criteria:
- Stable: The element is not currently animating.
- Visible: It has a non-empty bounding box and does not have
visibility:hiddenin its computed style. - Enabled: The element does not have a
disabledproperty. - Receives Events: The element is not covered by other elements.