AgentQL Query Introduction

The AgentQL query serves as the building block of your script. This guide shows you how AgentQL's query structure works and how to write a valid query.

Single term query

A single term query enables you to retrieve a single element on the webpage. Here is an example of how you can write a single term query to retrieve a search box.

{
    search_box
}

List term query

A list term query enables you to retrieve a list of similar elements on the webpage. Here is an example of how you can write a list term query to retrieve a list of prices of apples.

{
    apple_price[]
}

You can also specify the exact field you want to return in the list. Here is an example of how you can specify that you want the name and price from the list of products.

{
    products[] {
        name
        price
    }
}

Combining single term queries and list term queries

You can query for both single terms and list terms by combining the preceding formats.

{
    author
    date_of_birth
    book_titles[]
}

Giving context to queries

There two main ways you can provide additional context to your queries.

Structural context

You can nest queries within parent containers to indicate that your target web element is in a particular section of the webpage.

{
    footer {
        social_media_links[]
    }
}

Semantic context

You can also provide a short description within parentheses to guide AgentQL in locating the right element(s).

{
    footer {
        social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
    }
}

Syntax guidelines

Enclose all AgentQL query terms within curly braces {}. The following query structure isn't valid because the term "social_media_links" is wrongly enclosed within parenthesis().

( # Should be {
    social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
) # Should be }

You can't include new lines in your semantic context. The following query structure isn't valid because the semantic context isn't contained within one line.

{
    social_media_links(The icons that lead
        to Facebook, Snapchat, etc.)[]
}