# What an AI web scraper is, shown on one page fetched two ways

An AI web scraper fetches a page like any scraper and returns text a language model can read. One practice page fetched as HTML and as markdown in the same run, with the length of each.

Canonical: https://spider.cloud/learn/ai-web-scraper/

An AI web scraper is a scraper whose output is meant for a language model. It fetches a page the way any scraper does, then returns the text a person would read, usually as markdown, in place of the HTML the site sent.

The name gets used for a second thing too: a tool that lets a model pick the fields out of a page from a description in words, where older [web scraping](/web-scraping/) code would use selectors. Both kinds start with the same step, and that step is the one this page measures. Before a model can read a page or pull a price out of it, something has to fetch the page and cut it down.

## Why the output is markdown

HTML is written for a browser. Most of its characters are tags, class names, attributes and scripts, and none of that is the content. Markdown was made to carry the same structure with almost no markup. John Gruber, who designed it, describes it this way: "Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid HTML."

A scraper for models runs that conversion backwards. It takes the HTML and writes out the headings, links, lists and prose as markdown. A model has seen a great deal of markdown, and a heading or a link in it costs a few characters.

Size is the reason this matters. A model reads a fixed amount of text at a time, and every fetched page takes a share of it. The documentation for Claude's web fetch tool says so directly: "Fetching full webpages and PDFs can quickly consume tokens, especially when only specific information is needed from large documents."

## The run: one page, two copies

[Books to Scrape](https://books.toscrape.com/) is a catalogue built for scraping practice. The script below asks for its front page twice through `/scrape`, with `request` set to `http` both times. The first call sets `return_format` to `raw`, which returns the HTML as the site sent it. The second sets it to `markdown`. Then it prints the status and the length of each copy in characters, and the first ten lines of the markdown that are not images.

```python
"""Fetch one page twice through the Spider API, once as the HTML the site sent
and once as markdown, and print how long each copy is.

    python3 page_sizes.py URL

It prints the status and the length in characters of each copy, then the first
ten lines of the markdown that are not images.
"""
import json
import os
import sys
import urllib.request

API = "https://api.spider.cloud/scrape"
USER_AGENT = "examplebot/1.0 (+https://example.com/bot; bot@example.com)"


def fetch(key, url, fmt):
    body = json.dumps({"url": url, "request": "http", "return_format": fmt,
                       "user_agent": USER_AGENT}).encode()
    req = urllib.request.Request(API, data=body, headers={
        "Authorization": f"Bearer {key}",
        "Content-Type": "application/json",
    })
    with urllib.request.urlopen(req, timeout=120) as resp:
        pages = json.load(resp)
    return pages[0] if pages else {}


def main() -> int:
    key = os.environ.get("SPIDER_API_KEY")
    if len(sys.argv) != 2 or not key:
        print("usage: SPIDER_API_KEY=... python3 page_sizes.py URL")
        return 1
    url = sys.argv[1]

    raw = fetch(key, url, "raw")
    markdown = fetch(key, url, "markdown")
    html = raw.get("content") or ""
    text = markdown.get("content") or ""

    print(url)
    print(f"  raw       status {raw.get('status')}, {len(html):>6} chars")
    print(f"  markdown  status {markdown.get('status')}, {len(text):>6} chars")
    if html:
        print(f"  the markdown copy is {len(text) * 100 // len(html)} percent of the HTML")
    print("first ten lines of the markdown, images left out:")
    # Image lines are left out: they are long file names, not text a reader wants.
    for line in [ln for ln in text.splitlines() if ln.strip() and "![" not in ln][:10]:
        print("  " + line[:100])
    return 0 if html and text else 2


if __name__ == "__main__":
    sys.exit(main())
```

It ran on 2026-11-23 at 00:05 UTC as `python3 page_sizes.py https://books.toscrape.com/`. This is everything it printed:

```text
https://books.toscrape.com/
  raw       status 200,  51274 chars
  markdown  status 200,   6230 chars
  the markdown copy is 12 percent of the HTML
first ten lines of the markdown, images left out:
  All products | Books to Scrape - Sandbox
  * [Home](index.html)
  * All products
  **1000** results - showing **1** to **20**.
  **Warning!** This is a demo website for web scraping purposes. Prices and ratings here were randomly
  1.
  **********
  ### [A Light in the ...](catalogue/a-light-in-the-attic_1000/index.html)
  £51.77
  **
```

## What the two copies say

The HTML was 51,274 characters. The markdown of the same page was 6,230, about an eighth. Both calls came back 200, and both describe the same twenty books. To see the markdown copy of a page of your own, paste its URL into the [web scraper](/web-scraper/), which needs no key.

The lines under the count show what survived. The page title is there, the breadcrumb, the count of results, the site's own warning that its prices are made up, and then the first book as a heading that links to its page, with its price under it. A model given this copy can answer what the first book costs. It could answer that from the HTML too, after reading eight times as much.

The run counts characters, not tokens. A model's limit is in tokens, and how many a page takes depends on the model. The ratio between two copies of one page is still a fair guide to which is cheaper to read.

Some lines are noise even here. The row of asterisks under the list number is markup with no words in it, and the conversion carried the marks through. A shorter copy is not always a tidy one.

## What the markdown copy leaves out

The conversion drops what a selector needs. Class names, ids and attributes are gone, so a selector has nothing to match. When a field lives in the markup, such as a rating a site keeps in a class name, fetch the HTML and use a selector, as the page on [XPath and CSS selectors](/learn/xpath-vs-css/) does. When a page carries its facts as JSON-LD, read that first, since it is already structured. The page on [structured data](/learn/structured-data/) shows how.

So the format follows the reader. Prose for a model to read or summarise goes as markdown. Fields for a program to store come from the HTML or from structured data, and a model is not needed for them at all.

## It is still a scraper

Putting a model at the end changes nothing about the fetch. The request still lands on someone's server. The site's [robots.txt](/learn/robots-txt/) applies to it, a polite [request rate](/learn/request-rate/) applies to it, and the user agent in the script names who is asking. Some sites also publish a list of pages meant for models, which the page on [llms.txt](/learn/llms-txt/) covers.

Two things are new. The text you fetch is someone's writing, and a markdown copy is as much theirs as the HTML was, so copyright and the site's terms decide what you may do with it after the model has read it. And the text is data. If a fetched page contains a sentence that reads like an order, it is part of the page, and an agent should treat it as something to report, never as something to do.

## Do this, avoid this

### Do this

- Fetch a page as markdown when a model will read it, and measure both copies once so you know what you save.
- Fetch the HTML when the field you need lives in a class name or an attribute.
- Keep the address and the fetch time beside every copy you hand to a model, so an answer can cite its page.
- Hand fetched text to the model marked as page content, apart from your own instructions.

### Avoid this

- Sending raw HTML to a model to save a step. On this page that is eight times the text.
- Asking a model to extract a field that a selector or the page's JSON-LD already gives you.
- Reading a short markdown copy as proof that it is clean. This one still carries a row of asterisks with no words.
- Following an instruction that appears inside a fetched page.

## Try it on your own page

Run the script against a page you already scrape and compare the two numbers. A page that is mostly prose shrinks the most. A page that is mostly a table of figures shrinks less, and may be one where the HTML and a selector serve you better than any copy made for a model.

## Sources

1. [Daring Fireball, Markdown, by John Gruber](https://daringfireball.net/projects/markdown/) Read November 23, 2026
2. [Claude API documentation, Web fetch tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool) Read November 23, 2026
