How to scrape a whole website to Markdown

Get the list of pages first (most sites publish it at /sitemap.xml), then read each URL, convert its main content to Markdown and save one file per page. A reader API does the fetching and cleanup in one call and also handles pages built with JavaScript. Ours costs $0.02 per page, so a 300-page site is about $6; it reads one URL per call and doesn't follow links for you.

Try it free Read Any Web Page, PDF or Doc — clean Markdown for AI agents · $0.02 / call

One page is a call, a site is a project

Reading a single page is one request. A whole site adds three jobs: finding every address, looping over them without upsetting the server, and storing the results so you can update them later.

Crawlers find pages by following links, which also picks up tag pages, search results and endless calendars. The sitemap is usually the cleaner list, because the site owner wrote it for search engines.

The plan

  1. Open https://the-site.com/sitemap.xml. If it lists more sitemaps (a sitemap index), read each of those too. robots.txt often names the sitemap on a Sitemap: line.
  2. Filter the list: drop tag, author, page-2 and login addresses you don't need.
  3. Read each address into Markdown and save it as a file named after its path.
  4. Keep the lastmod date from the sitemap, so the next run only reads pages that changed.

A Node.js script

Node 18 or newer. payFetch stands for the fetch function your x402 v2 client gives you: it pays the 402 answer in USDC on Base and repeats the request.

import { writeFile, mkdir } from "node:fs/promises";

const READER = "https://iamai.markets/api/x402/services/XyehnOmhOzAF";
const xml = await (await fetch("https://example.com/sitemap.xml")).text();
const urls = [...xml.matchAll(/<loc>(.*?)<\/loc>/g)]
  .map((m) => m[1])
  .filter((u) => !u.includes("/tag/"));

await mkdir("site-md", { recursive: true });
for (const url of urls) {
  const r = await payFetch(READER, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ url, max_chars: 100000 }),
  });
  if (!r.ok) { console.log("skipped", url, r.status); continue; }
  const { result } = await r.json();
  const name = new URL(url).pathname.replace(/^\/|\/$/g, "").replaceAll("/", "_") || "index";
  await writeFile(`site-md/${name}.md`, `# ${result.title}\n\nSource: ${result.url}\n\n${result.markdown}`);
  await new Promise((done) => setTimeout(done, 500)); // be gentle with the site
}

Cost and limits for a full run

Scraping manners

Tools for whole-site jobs

ToolHow it finds pagesWhat you run
FirecrawlCrawls by following links, or maps a siteHosted service with plans, or the open-source version
crawl4aiCrawls by following linksOpen-source Python library on your machine
Jina ReaderOne URL at a time (r.jina.ai/ + URL)Hosted service
Page reader API (iamai.markets)One URL at a time; you bring the listNothing: $0.02 per page, paid per call with x402

The product

Questions

What if the site has no sitemap?

Read the homepage, then collect the links in its Markdown that point to the same domain. Repeat one level down for the main sections. That covers most small sites.

Can it read members-only pages?

No. It opens pages the way a logged-out visitor does, so anything behind a login stays out of reach.

How do I keep the files current?

Store each page's lastmod from the sitemap next to its file. On the next run, only read the addresses whose date has changed.

Related

Updated 2026-12-01