AgentQL Quick Start
This guide will get you started with the basics of AgentQL queries, how to use the Chrome extension for debugging, and how to implement queries using AgentQL's Python SDK.
What is an AgentQL query?
AgentQL is a query language and a set of supporting developer tools designed to identify web elements and their data using natural language and return them in the shape you define.
Here is an AgentQL query you can use right now to locate the search button on this page:
This query can return each heading on this page:
The following will show you how to execute queries to retrieve data and elements from web pages starting right here, with the page you are on now.
Get your API key
You need an API key to make AgentQL queries. Get one in our DevPortal, and you'll be ready to go!
Query this page with the AgentQL Debugger Chrome extension
The AgentQL Debugger lets you write and test queries in real-time on web pages, without needing to spin up the Python SDK. It's perfect for debugging queries before putting them into production! Here's how to get started:
-
Install the AgentQL Debugger from the Chrome Web Store.
-
Come back to this page and open Chrome DevTools (Ctrl+Shift+I on Windows/Linux or Cmd+Opt+I on Mac).
-
In the top bar of the devtools panel, select "AgentQL".
-
Enter your API key when prompted.
-
In the query panel, try this query:
- Click "Fetch Web Elements" to run the query to return the search button element.
In the AgentQL tab, you will find an entry for the search button. If you hover over it you will see it highlighted on the page.
Try it out!
The best way to learn how AgentQL works is to play around with it in the extension. Here are some things you can try:
- Click the eye icon, and you will navigate to the element on the page.
- Click
</>
, and you will navigate to the element in the devtools. - Click "Fetch Data" to return the contents of the queried elements instead of the elements themselves (great for scraping).
- Use
[]
to return a list of items. - Use
()
to add additional context to find the exact element:
Experiment with different queries to get a feel for how AgentQL works. For example, try this one out with "Fetch Data" to get a list of all the headings on this page:
You can even nest items:
Perform the query with the AgentQL Python SDK
Now that you're familiar with writing queries, let's use the Python SDK to run the same query programmatically.
- In you project folder, install the AgentQL SDK and initialize AgentQL:
- Provide your API key.
- Create a new Python file,
example_script.py
. - Add the following code:
- Run the script:
This script will open this site, docs.agentql.com, click the search button, fill the search modal's input with "Quick Start," and click on the first result—bringing you back to this page.
Next steps
Congratulations! You've now used AgentQL queries both in the Chrome extension and the Python SDK. This is usually how you will work with AgentQL: optimizing and debugging queries with the extension before running them in Python scripts with the SDK.
Here are some next steps to explore:
- Learn more about AgentQL query syntax
- Explore best practices for writing queries
- Check out an example script for collecting YouTube comment data
Happy querying with AgentQL!