Skip to content

sitegraf

An alternative to website to Markdown for LLM input: a CLI that renders a site in a real browser and writes one validated JSON file.

On this page

Feed a language model raw HTML and you are paying it to read wrapper divs. Converting a website to Markdown for LLM input is a common cure, and it flattens a lot on the way down. sitegraf takes another exit: it opens a site in a real browser and writes the visible content and its structure into one JSON file a model can read.

Website to Markdown for LLM input, minus the Markdown

The design document opens with the whole product in one line: a URL goes in, website.json comes out. Headings, paragraphs, lists, tables, links, calls to action, navigation, image URLs with alt text, form labels and footers, with nesting preserved. A feature group that contains features stays a group that contains features.

The first question the design settled was who reads it. A model does. That makes output size a real constraint and not a cleanup task for later. It also killed a feature before birth. An earlier draft asked what to do when a per node classification scored low confidence. The answer was to delete the classification: structure is expressed by where something sits in the schema. The note reads, “A contract with no consumer is a liability.”

Here is a sketch of the shape, trimmed to the idea:

json
{
  "site": { "title": "...", "nav": { "items": [] }, "footer": { "links": [] } },
  "pages": [
    {
      "route": "/pricing",
      "status": "ok",
      "hero": { "title": "...", "actions": [] },
      "sections": [{ "heading": "...", "content": [], "items": [] }]
    }
  ],
  "extraction": { "outcome": "complete", "skipped": [] }
}

A real browser, then one hard look

Plenty of pages don’t exist until JavaScript has run, so sitegraf renders them with Playwright. It waits for the DOM to hold still (half a second without a mutation, capped at 8 seconds), scrolls to the bottom to wake lazy content, waits for stillness again, switches off animations and returns to the top.

Then it takes the snapshot in a single evaluation inside the page. The result is a flat list of nodes with parent pointers. Each carries its semantic role, heading level, link, media, position in document coordinates, a few computed styles and a signature of its shape. A node keeps only its own direct text, so one sentence isn’t repeated by every ancestor above it. Hidden things are dropped: display: none, zero opacity, zero area, aria-hidden. Form controls are described by type, name and placeholder. The snapshot is validated against a Zod schema before anything else sees it.

Impure browser, pure analyzer

This is the seam the whole design hangs on. Everything that touches the network and the browser sits on one side. The work of making sense of the page sits on the other, and only plain data crosses.

flowchart LR
  subgraph live["Browser and network"]
    direction TB
    queue["Crawl queue"] --> render["Render until still"]
    render --> snap["One snapshot in the page"]
  end
  subgraph pure["No browser needed"]
    direction TB
    analyze["Analyzer"] --> serial["Serializer"]
  end
  live -->|"validated"| pure
  pure --> file["website.json"]

The analyzer never sees a browser. Snapshot in, page structure out. Inside it, the work goes roughly like this:

flowchart TD
  nodes["Flat list of nodes"] --> marks["Find navigation, main and footer"]
  marks --> wrap["Walk through lone wrappers"]
  wrap --> bands["Wide horizontal bands become sections"]
  bands --> same["Same shaped siblings become items"]
  same -->|"and again inside each item"| same
  bands --> rest["Headings, text, lists, tables, actions"]
  bands --> hero["First section, if it has the h1: hero"]

Landmarks are found by semantic role, with a fallback that treats a cluster of links near the top as navigation. The wrapper walk only passes through a lone child that occupies the same rectangle as its parent, which is how it wades through div soup. The recursion is what turns a pricing grid into entries instead of a wall of text. A heading is a semantic heading, or failing that the largest type in the section. Once every page is in, navigation and footers that repeat move up to the site level and are stated once.

A polite guest

A crawler is a visitor, and visitors have manners. sitegraf reads robots.txt and has no flag to ignore it. A site crawl honours Crawl-delay and waits at least a second between page loads. On a 429 or 503 it backs off and respects Retry-After. Pages marked noindex or nofollow are treated accordingly. Login walls are skipped.

If a site puts up a bot challenge, sitegraf marks the page blocked, stops, and writes out what it has. It never tries to get around one. Recognising a challenge takes evidence: an early version treated an ordinary CDN header as a block, which is like assuming every building with a doorman has barred you. The detector now wants proof of an actual challenge.

Partial runs still count

Crawls get interrupted. After each URL, sitegraf writes a checkpoint to a temporary file and renames it into place, so the file on disk is whole. A cancelled or failed run still produces an artifact that passes the schema.

And the artifact is honest about itself. Every page says how it went:

Page statusWhat it tells the reader
okextracted normally
suspectthin result, read with care
blockeda bot challenge, so the crawl stopped
errorthe page failed to render

So does the run as a whole:

Run outcomeMeaning
completeran to the end of its queue
truncateda page, depth or time budget cut it short
haltedstopped early, for example by a cancel
failednothing usable came out

A mid run checkpoint even labels itself halted, so half a crawl never poses as a whole one. The extraction block also records which limits applied and which URLs were skipped and why. A model reading it can tell “this site has no pricing page” apart from “the crawl stopped before pricing”, and those two deserve very different answers.

URL handling is just as deliberate. Tracking parameters are stripped, and the query parameters that remain are sorted into a stable order. A cap per path template keeps a faceted shop from spending the whole page budget on one listing in fifty colours.

The choices I didn’t make

Rust for the analyzer was proposed and rejected. The geometry it needs only exists inside the browser, so the data would have to cross a process boundary to speed up a step that the design estimated at around 0.1 percent of wall clock. That is an estimate, and still an easy call: page loads are the slow part.

Postgres was rejected too. A single crawl of a single origin holds nothing that must outlive the process. A set handles deduplication and a JSON file handles checkpoints.

sitegraf also isn’t a feature inside longshot, my screenshot tool. longshot’s manifest is shaped around image files, so teaching it to extract structure meant operating on every consumer of that shape. A new repository was cheaper.

sitegraf is TypeScript on Node 20 or later, version 0.1.0, private and unreleased, with its first commits dated 22 August 2026.