Home/Guides/Web scraping for AI agents
Guide

Web scraping for AI agents: a practical guide

Web scraping for AI agents is getting web content into a form a model can use: the passages that answer, rows from a known site, or a short view of a page the agent acts on. It differs from classic scraping because every token you hand the model costs money and attention.

94.5%fewer tokens on 8 long pages by sending passages: 187,718 → 10,325
98.4%fewer tokens for 50 SEC filings as rows: 211,652 → 3,301
10.3×fewer tokens than Playwright MCP on the same 10 browser tasks
The short answer

What should you remember?

01

Output is for a model

Markdown, passages or rows, never raw HTML, and as few tokens as the job needs.

02

Pick the cheapest way in

A feed or API first, then the page, then a browser only when you must click.

03

Be a polite client

Respect robots.txt, keep the rate low, never fake being a person.

How is scraping for AI different from classic scraping?

Classic scraping fills a database: you want every field of every row, and size does not matter much. Scraping for an AI agent fills a context window: you want what answers the question, in plain text, at the fewest tokens, and often right now rather than overnight. Agents also act: they log in, click and fill forms, which a crawler never does.

What are the four ways to give an agent the web?

WayWhat the model getsUse it whenMeasured
ReadThe passages of a page or PDF that answerThe agent has a URL and a question94.5% fewer tokens on 8 long pages
SearchSentences from live results, with sourcesThe agent needs to find pages first86.3% fewer tokens for one question
ExtractRows from a known kind of site, by codeJobs, stores, reviews, filings, news98.4% fewer tokens for 50 filings
BrowseA ranked view of the page, then the changesLogins, clicks, forms19× fewer tokens over 3 tasks

How do you handle JavaScript pages, PDFs and logins?

  • JavaScript pages: render them in a real browser, then read the text; remember which sites need it so the next read goes straight there.
  • PDFs and Office files: parse the text layer, run OCR when a scan has none, and return the passages that answer; a 152-page annual report came to 1,277 tokens for one question instead of 140,355.
  • Logins: use saved sessions or a secrets vault, so the model never sees a password, and ask a person before anything that pays, sends or deletes.

How do you stay polite and legal?

Respect robots.txt, keep the request rate low, and stop when a site challenges you instead of trying to get around it. Identify your agent honestly; signed agent identity lets sites see who is browsing. You are responsible for the sites you read and the data you keep: check the site's terms, avoid personal data you do not need, and redact what you keep. This is not legal advice.

Should you build it or use an API?

A scraper for an AI agent needs rendering, boilerplate removal, a ranker, parsers for PDFs and Office files, OCR, change detection, a browser with approvals and code for the sites you read most. Build it when scraping is your product; use an API when it is a step in your agent. The comparison of seven says when each one is the better pick, including when it is not us.

Measured, not promised

What did we measure?

Runs recorded with their date and their limits; your own numbers appear on every call.

94.5%fewer tokens on 8 long pages by sending passages: 187,718 → 10,325
98.4%fewer tokens for 50 SEC filings as rows: 211,652 → 3,301
10.3×fewer tokens than Playwright MCP on the same 10 browser tasks
FAQ

Questions people ask

Is web scraping for AI legal?

It depends on the country, the site's terms and the data. Public pages are generally readable, but personal data and copyrighted text carry rules of their own. This is not legal advice.

What format should scraped content be in for an LLM?

Markdown or plain passages, not HTML. Markup can be several times the size of the text and carries nothing the model needs.

How do I scrape JavaScript-heavy sites for an LLM?

Render the page in a real browser, wait for the content, then read the text and send the passages that answer.

Spend tokens on answers, not on pages.

Create a workspace in a minute. Connect ChatGPT, Claude, Cursor or your own agents. Every answer comes with the token savings.