An AI web scraper that runs without the AI
A LangGraph.js agent writes a typed scraper once; every run after replays it with zero model calls.
Our workflow platform already had a web scraper. A person recorded a live browser session, the recording became a script, and runs went through a job queue with a pause for a person when a CAPTCHA appeared. What it could not do was understand a page. Every script was hand-made, every element was found by one CSS selector, and when a site renamed a class the step failed and nothing repaired it.
Over about three weeks I turned it into an AI-assisted scraper. A person describes the data in plain English, an assistant builds and tests the scraper on a live browser, and every saved run after that replays the result with no model call at all.
The rule: the model writes the recipe once
One idea shaped every decision. A model is good at reading an unfamiliar page and proposing how to pull data out of it. It is a poor thing to keep inside every scheduled run, where it adds cost, latency and a fresh way to be wrong.
So the assistant's job is to produce a typed script. The runner executes that script exactly. The model only comes back when something breaks, and even then it proposes a fix for a person to approve.
I borrowed ideas from open source to get there. Stagehand plans an action separately from running it. Browser Use shows the model an indexed list of page elements and lets code build the locator. Crawl4AI generates an extraction schema once and runs it without a model. The only thing we embedded was Microsoft's Playwright MCP, for driving the browser.
A typed recipe that people and the model share
Everything rests on a versioned script format, validated with Zod when it is saved, when the model proposes a change, and before a run is queued. The manual steps editor and the assistant write the same format, so a scraper built by one can be edited by the other.
- Several ways to find each element. A locator is a list of strategies tried in order: role and accessible name, test id, label, text, CSS, XPath. The first unique match wins. Each locator also keeps a fingerprint of the element and a plain description such as "Search results table".
- Real control flow. Pagination (next button, URL pattern, infinite scroll, load more), opening each link in its own tab, conditions, waits, assertions, logins and downloads.
- Secrets the model never sees. A login step points at a runtime parameter by name. The value is encrypted at rest, masked in logs and chat, and typed into the page by the runner.
- Old scripts keep working. A first-version script is upgraded when it runs, and its CSS selector becomes a one-strategy locator.
Propose, approve, then act
The assistant is a LangGraph.js agent inside the existing NestJS service. It drives the browser through Playwright MCP, attached over the Chrome DevTools Protocol to the same browser the person is already watching, so they can see every move and take over at any time.
Tools that read run freely: list configurations, read the page, find repeating structures, test steps on the live page. Tools that change something pause the agent and show a proposal card with evidence: the script diff, the validator's result, a dry run on the live page and five sample rows. Nothing is saved or run until the person clicks Accept. Because the model cannot approve its own actions, text hidden in a scraped page cannot make it save or run anything.
An eval suite runs the assistant against fixture sites we host, with tables, cards, pagination, logins and iframes. It passed all eight tasks against the real model once we fixed what the real model exposed.
Keep going until the rows are right
The first live tests taught me that a working assistant is not the same as a finished scraper. It proposed steps, said it was running, and stopped. Runs that returned zero rows were marked complete. We closed that gap in four layers, each added because the one above it was not enough on its own:
- Prompt rules. Test, run, wait for the result, check the rows, fix failures up to three times, then save and close the browser.
- A finish guard in code. After each reply it reads the tool results. If steps were accepted but never run, or a run was never waited on, it tells the model to continue, up to three times.
- Summaries that expose bad data. Every run reports rows per output, how many rows miss each field, and any field with the same value in every row. That last check exists because one demo run filled every summary with the word "Share", the page's share button, and the assistant called it a success.
- Warnings for the person. A card now warns when a change stops collecting a field the person asked for.
Self-healing, cheapest fix first
When every strategy in a locator fails, the runner heals it in tiers: the next strategy in the list, then a fingerprint match against nearby elements, then a model repair that is rate-limited per site, then a clear failure with a repair proposal. Only the third tier calls a model. By default a healed locator is used for that run and saved as a proposal for a person to approve.
One bug hid behind passing tests. Healing worked, but none of the code paths that queued a run passed the scraper's id, so every repair was thrown away and re-healed on the next run. Once fixed, the run after an approved repair passed that step on its first try in 1.9 seconds instead of 19.
A real run
The proving case used only public pages. In one message: start at a public resource library, page through all five pages of its list, follow only the press releases (which live on a different site), and extract each title, a summary and the PDF link. The assistant proposed allowing both sites, built a paginate step with a for-each inside it, hit an element-not-found on the first click, repaired it, ran, noticed a missing field, added it and ran again. The finished scraper returned 9 records in 18 seconds, with no "continue" typed by anyone.
What I would tell another team
- Keep the model out of the run. Let it write a typed recipe and fix it when it breaks. Healthy runs should make zero model calls.
- Give every element several ways to be found. Multi-strategy locators plus a fingerprint make most repairs free.
- Make the model prove its work with data it can see. Row counts and empty-field counts caught more bad scrapers than any prompt rule.
- Back prompt rules with code. "Keep going until done" only held once a guard enforced it.
What it unlocked
The work landed as 21 backend and 7 UI commits with 400+ unit tests, and the scraper is now used by two business units. It changed how I think about AI features in general: the most useful place for a model is often at build time, writing something deterministic that people can read, test and approve.