skip to content
all examples

Scraping a website with e2e core

A script that collects every Science Fiction book from Books to Scrape with @e2e-dev/core, the agent navigating and extracting data with no CSS selectors.

A scraper that collects every Science Fiction book from Books to Scrape, used as an example of running the e2e agent outside a test run.

How it works

The scraper is a single script, scraper/scrape-sci-fi.ts. It launches a browser with @e2e-dev/core and @e2e-dev/web, then lets an agent do the work:

  • Navigation uses agent.act to open the category and go to the next page of results. After each step, an exact locator waits for the expected heading or page number to confirm the agent ended up in the right place.
  • Extraction uses agent.extract with a Zod schema. On each listing page it reads the book URLs, the result count, and whether there's a next page. On each book page it reads the title, price, stock, UPC, rating, review count, and description. The rating is shown as stars, so book pages are read with vision: true.
  • Output goes to output/science-fiction.json. The script checks that it found as many books as the category says it has.

The script has no CSS selectors: the agent finds links and reads values from what's on the page.

Cache

Each agent.act step is recorded in .scraper/cache the first time it runs. Later runs replay the recording without calling the model. agent.extract calls the model on every run, because the page content is what you're after.

Output

json
{
  "category": "Science Fiction",
  "scrapedAt": "2026-11-27T13:46:46.220Z",
  "books": [
    {
      "title": "Join",
      "price": 35.67,
      "inStock": true,
      "upc": "18ad3ed896c7ce05",
      "rating": 5,
      "stockCount": 16,
      "numberOfReviews": 0,
      "description": "What if you could live multiple lives simultaneously, …",
      "url": "https://books.toscrape.com/catalogue/join_902/index.html"
    }
  ]
}

Getting started

You need Node.js 24 or later, which runs the TypeScript script directly.

terminal
npm install
npm run scrape

The agent model goes through the Vercel AI Gateway, so set AI_GATEWAY_API_KEY (or link a Vercel project). To use a different model, set SCRAPER_MODEL to a gateway model ID (the default is openai/gpt-6-luna-fast).

To watch the browser while it scrapes:

terminal
npm run scrape:headed

To scrape another category, change CATEGORY and OUTPUT at the top of the script.

Scripts

CommandDescription
npm run scrapeScrape the Science Fiction books
npm run scrape:headedScrape with a visible browser
npm run formatFormat with Prettier

[ get started ]

your verificationlayerstarts withjust one command

npx e2e init