Convert a website to Markdown for LLMs and RAG

You want a chatbot that answers questions about your docs, or an agent that knows your help centre. The first job is always the same: turn a website into clean text an LLM can use, without the menus, footers and cookie banners that waste tokens and confuse retrieval.
I built a crawler for this. It fetches pages over plain HTTP, keeps the main content and returns one row of Markdown per page. Here's what matters if you do the same.
What to watch for
- No JavaScript rendering. A single-page app that ships an empty HTML shell comes back thin or empty. Those rows are flagged
needsJavaScript: true, and rows with no text at all are not charged. Server-rendered sites work: most documentation generators, WordPress, Ghost, static sites and Next.js with SSR. - Scope follows the start URL's path.
https://example.com/docscrawls/docsand everything below it. Start from a single page like/docs/quick-startand you get only that page. Start higher, or setincludeGlobsto["/docs/**"]. - Main content is detected, not guessed. It uses
<main>when present, then the<article>holding the H1, then a text-density heuristic. If a site keeps unwanted blocks, add them toremoveSelectors; if the wrong area is picked, setkeepSelectors. - Gzipped sitemaps (
.xml.gz) are not read. The crawler then relies on links. - PDFs and images are skipped, counted and not converted.
- Tables survive. Data tables become GitHub-style Markdown tables, though row spans are flattened.
- robots.txt is respected by default, for the user agent
WebsiteContentCrawler.
Getting the data
I packaged this as an Apify Actor, Website Content Crawler. A row from a crawl of the Apify Academy docs looks like this (Markdown shortened):
{
"url": "https://docs.apify.com/academy/tutorials",
"title": "What's this section? | Academy | Apify Documentation",
"language": "en",
"markdown": "# What's this section?\n\n**Learn about various different specific topics related to web-scraping and web-automation with the Apify Academy tutorial lessons!** ...",
"wordCount": 81,
"tokensEstimate": 133,
"headings": [{ "level": 1, "text": "What's this section?" }],
"depth": 1,
"referrerUrl": "https://docs.apify.com/academy",
"statusCode": 200,
"contentHash": "f82e8e5193bd072a",
"needsJavaScript": false
}
headings gives you the H1 to H3 outline for chunking, and tokensEstimate (characters divided by 4) tells you which pages need splitting before embedding.
From the command line:
curl -X POST "https://api.apify.com/v2/acts/rjmacarthy~website-content-crawler/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"startUrls": [{ "url": "https://crawlee.dev/sitemap.xml" }],
"crawlMode": "sitemap",
"includeGlobs": ["/blog/**"],
"maxPages": 100,
"includeLinks": false
}'
crawlMode is site (follow links under the start path), sitemap (only the pages in the sitemap) or urls (exactly the URLs you give). Turning includeLinks off keeps the link text and drops the URLs, which saves tokens. Add "outputFormats": ["markdown", "text"] if you also want plain text.
Keeping a vector database fresh
Re-embedding a whole site every night is wasteful when a handful of pages changed. Set monitorMode to changed:
{
"startUrls": [{ "url": "https://docs.python.org/3/tutorial/" }],
"maxPages": 500,
"monitorMode": "changed",
"stateKey": "python-tutorial"
}
- The first run saves every page and remembers a hash of each one.
- Schedule it nightly in Apify. Later runs output only new pages and pages whose text changed, marked
changeType: "new"or"changed". - Trigger your embedding job from a webhook when the run succeeds, and re-embed only those rows.
The hash covers the page title and text, so a new build ID or a tracking parameter doesn't count as a change, while any edit to the visible text does. Two caveats: deleted pages are not reported, and you should keep maxPages above the size of the site, otherwise different pages may be reached on different nights. Use one stateKey per site.
What it costs
It's $0.0005 per page saved ($0.50 per 1,000) on every Apify plan, plus $0.00005 per run. Compute is included, so the cost doesn't depend on how slow the site is: maxPages times $0.0005 is the most a run can cost. A 200-page docs site is $0.10.
Failed pages, out-of-scope redirects, non-HTML files, URLs blocked by robots.txt, pages with no text and, in monitor mode, unchanged pages are not charged. A nightly run over a 1,000-page site where 12 pages changed costs $0.006.
It reads publicly reachable pages only, with no login.