NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

AI agents and automation

How AI agents are used in web scraping

Language models changed some parts of scraping a lot and others hardly at all. This article sorts the useful roles of agents in a scraping pipeline from the ones that are better left to plain code.

The useful roles, in brief

Agents earn their place in four jobs: planning how to reach the data on an unfamiliar site, extracting fields from pages whose layout varies, repairing selectors when a site changes, and handling one off tasks that are not worth a dedicated scraper. They are a poor fit for high volume fetching, exact numeric extraction at scale, and anything where cost per page matters more than flexibility. Most good pipelines use both: code for the repeatable path, a model for the parts that change.

Planning: finding the path to the data

On a new site, the hard part is often not parsing but navigation. Where is the category list? Does search have filters? Is there pagination or infinite scroll? An agent with a browser can explore a site the way a person would and write down the route: "start at /categories, open each link, the product grid uses ?page=N". That route can then become a deterministic crawler.

The pattern to aim for is explore once with the agent, run many times with code. Running the agent for every crawl repeats expensive reasoning that produced the same answer last time. The web crawling entry covers the crawler side.

Extraction: turning pages into records

This is where models shine. Product pages, job listings, company profiles and event pages from different sites hold similar facts in very different markup. A model given the page text and a schema can fill in name, price, currency, availability and attributes without a selector per site.

listing_schema = {
    "type": "object",
    "properties": {
        "title": {"type": "string"},
        "price_amount": {"type": "number"},
        "price_currency": {"type": "string"},
        "in_stock": {"type": "boolean"},
        "seller": {"type": ["string", "null"]},
    },
    "required": ["title", "price_amount", "price_currency", "in_stock"],
}
# Send the cleaned page text plus this schema to a model that supports
# structured output, then validate the reply before storing it.

Two habits make this reliable. First, shrink the input: strip scripts, navigation and footers before sending text to the model, which cuts cost and confusion. Second, validate: check that prices are positive, currencies are real codes, and required fields exist, and send failures to a review queue. Where the page has structured data such as schema.org markup, read that first and use the model only for what is missing.

Self healing selectors

Classic scrapers break when a site renames a class. A practical middle ground keeps CSS selectors for speed, and calls a model only when a selector returns nothing. The model receives the old selector, a sample of the page and a description of the field, and proposes a new selector. Code tests it against a few pages; if it works, the scraper saves it and continues.

This keeps the cost of the model proportional to how often the site changes, not to how many pages you fetch. It also leaves a history of selector changes that makes debugging easy. See CSS selectors for the basics.

One off and long tail tasks

Some jobs are too small for a scraper: collect the opening hours of thirty local shops, check which of fifty vendor pages mention a certain certification. An agent can do these end to end in an afternoon, and nobody has to maintain the code afterwards.

The limits worth knowing

Cost and speed

A model call per page costs far more than parsing HTML with a library, and it takes seconds instead of milliseconds. At thousands of pages a day, that difference decides the architecture.

Accuracy on numbers

Models occasionally misread or invent values, especially when a page shows several prices (list price, sale price, per unit price). Always validate numeric fields against the page text, and prefer deterministic extraction for them where possible.

Access is unchanged

An agent does not make a site easier to reach. It uses the same browser and network as any scraper, and sites apply the same checks. Rate limits, IP reputation and CAPTCHAs affect agents exactly as they affect scripts, and sometimes more, because agents explore aggressively.

CAPTCHAs in an agent assisted pipeline

Treat CAPTCHAs as an infrastructure concern, not an agent concern. The fetch layer, whether it is a browser pool or an HTTP client, detects a challenge, calls a CAPTCHA solving API, places the token or cookie, and returns the page. The model receives clean content and never needs to know a challenge happened.

That separation keeps things simple. The same solving code serves the deterministic crawler and the exploring agent. Costs are predictable per type, for example $0.56 per 1,000 for reCAPTCHA v2 or $1.40 for the AWS WAF cookie, and only successful solves are charged. Our article on CAPTCHA solving in web scraping walks through where the solve belongs in the request flow.

A sensible architecture

LayerDone byWhy
Discovery of routes on a new siteAgent, onceFlexible on unknown layouts
Scheduled fetchingCodeFast, cheap, repeatable
Challenges and CAPTCHAsFetch layer plus solving APIInvisible to the rest of the pipeline
Extraction of stable fieldsSelectors or structured dataExact and cheap
Extraction of messy fieldsModel with a schemaHandles layout variety
Selector repairModel on failure onlyCost scales with change, not volume
ValidationCodeCatches model mistakes

Scope and respect for sites

Agents make it easy to scrape more than you need. Collect public data, keep request rates polite, honor clear restrictions and prefer official APIs where they exist. Personal data needs a lawful basis; our article on whether web scraping is legal covers the main questions. Done this way, agents are a genuine productivity gain rather than a source of blocks.

Costs in practice

It helps to put rough numbers on each part before choosing a design. Parsing a page with a library costs effectively nothing beyond the fetch. A model call costs a fraction of a cent to a few cents depending on the model and how much text you send, and adds a second or more of latency. A CAPTCHA solve costs its per type rate, but only when a challenge appears. Fetching itself, through a browser pool and good network, is often the largest line. Seen that way, it is obvious why agents belong in discovery and repair rather than in the hot path: their cost scales with the number of pages, while discovery and repair scale with the number of sites and changes.

Measuring whether the agent helps

Track the share of pages that needed the model fallback, the accuracy of model extracted fields against a sample you check by hand, and the time from a site redesign to a working scraper again. If the fallback share stays high for a site, that site deserves proper selectors. If repair time dropped from days to minutes, the agent is earning its keep.

Common questions

Should an AI agent fetch every page in a large crawl?

Usually not. Let the agent discover routes once, then run a code based crawler on that plan for the repeated work.

Are model extracted prices reliable?

Mostly, but pages with several prices can confuse a model. Validate numbers against the page text before storing them.

What is a self healing selector?

A selector that, when it stops matching, is replaced by a new one proposed by a model and tested by code before use.

Do agents get fewer CAPTCHAs than scripts?

No. They use the same browsers and networks, and their exploring tends to trigger checks at least as often.

Where should CAPTCHA solving sit in an agent pipeline?

In the fetch layer, so both crawlers and agents receive clean pages and the model never deals with challenges.

Keep reading