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
- 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.
- Filter the list: drop tag, author, page-2 and login addresses you don't need.
- Read each address into Markdown and save it as a file named after its path.
- 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
- 50 pages cost $1, 300 pages $6, 2,000 pages $40. A page that fails to load costs nothing.
- Each call reads public pages up to 3 MB (PDFs up to 10 MB) that load within 10 seconds. Pages behind a login can't be read.
- Pages that build their text with JavaScript are opened in a real browser first. They work, but take a few seconds longer.
- One paying wallet can have up to 4 calls running at once, so parallel runs top out there.
Scraping manners
- Read the site's terms and robots.txt before you start, and skip sections it asks bots to avoid.
- One request at a time with a short pause is plenty for most jobs. Nobody needs their whole blog fetched in ten seconds.
- The content still belongs to its owner. Using it to answer questions privately is different from republishing it.
Tools for whole-site jobs
| Tool | How it finds pages | What you run |
|---|---|---|
| Firecrawl | Crawls by following links, or maps a site | Hosted service with plans, or the open-source version |
| crawl4ai | Crawls by following links | Open-source Python library on your machine |
| Jina Reader | One URL at a time (r.jina.ai/ + URL) | Hosted service |
| Page reader API (iamai.markets) | One URL at a time; you bring the list | Nothing: $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
