Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 2 min read

How to turn a whole documentation site into clean Markdown for RAG (no headless browser)

You want your docs, help centre or blog inside a RAG pipeline or an AI agent's context. Raw HTML is the wrong input: half the tokens are navigation, cookie banners, footers and sidebar links, and the code blocks lose the

You want your docs, help centre or blog inside a RAG pipeline or an AI agent's context. Raw HTML is the wrong input: half the tokens are navigation, cookie banners, footers and sidebar links, and the code blocks lose their line breaks.

Here is the approach I use to get a whole site into clean Markdown, one row per page, ready to chunk.

1. Start from the sitemap, not from link-following

Most docs sites publish a sitemap.xml. Reading it gives you every page in one request instead of discovering them by crawling. Keep link-following (depth 1-2) for sites without a sitemap, and keep the crawl inside the start folder so you don't wander into the marketing site.

2. Keep only the main content block

Detect the article / main element and drop everything else: nav, header, footer, table of contents, "share this" boxes, consent banners. Data tables should become Markdown tables and code blocks should keep their language tag and line breaks, or your chunks will be useless for code questions.

3. Record a token estimate per page

characters / 4 is a good-enough budget for English with GPT- and Claude-style tokenizers. With it you can decide per page whether to chunk, truncate, or skip thin pages entirely.

4. Hash the content so re-runs only pick up changes

Store a hash of each page's Markdown. On the next scheduled run, unchanged pages are skipped and only new or edited ones go back into the vector store.

Example output

Real rows from a 10-page crawl of the Apify Academy JavaScript course (depth 1):

Page Words Est. tokens Headings Depth
Web scraping basics for JavaScript devs 960 1,881 23 0
Downloading HTML with Node.js 1,274 2,508 8 1
Parsing HTML with Node.js 1,176 2,235 6 1
Extracting data from HTML with Node.js 1,728 3,414 9 1
Getting links from HTML with Node.js 1,551 3,314 8 1

Each row carries markdown, title, description, h1, headings, wordCount, estimatedTokens, language, canonicalUrl, modifiedAt, contentHash and changeStatus.

I run this with my Website to Markdown Crawler ($0.30 per 1,000 pages, no start fee; failed pages, robots.txt skips and PDFs are free). It is plain HTTP, no headless browser: a 714-page docs site from its sitemap took 38 seconds in a local test. Input for a whole docs site:

{
  "startUrls": ["https://crawlee.dev/js/docs"],
  "useSitemaps": true,
  "maxCrawlDepth": 0,
  "maxResults": 0,
  "maxConcurrency": 20
}

From Python, straight into your chunker:

# pip install apify-client
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("rel8ble/website-to-markdown-crawler").call(run_input={
    "startUrls": ["https://crawlee.dev/js/docs"],
    "useSitemaps": True,
    "maxCrawlDepth": 0,
    "maxResults": 0
})
for page in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(page["finalUrl"], page["estimatedTokens"])
    # split page["markdown"] on "## " headings and embed

For a weekly refresh, add "changeTrackingStore": "my-docs-monitor" and only new or changed pages are saved (and charged).

One honest limit: it reads the HTML the server sends, so single-page apps that build all content in the browser come back thin. Docs, blogs, wikis and most company sites are server-rendered and work fine.

Using Claude, Cursor or another MCP client? Add https://mcp.apify.com?tools=rel8ble/website-to-markdown-crawler as a remote MCP server and ask in plain English.

Disclosure: I built and maintain this crawler; it is a paid Apify actor (pay per result, Apify's free plan credit covers small tests). The sample rows above are real output from a test run.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.