# Docs to Markdown: Crawl Any Docs Site for LLM & RAG (`heyiambk/docs-to-markdown`) Actor

Turn any documentation site into clean, LLM-ready Markdown for RAG, AI agents and knowledge bases. Crawls sitemap.xml and in-scope links, strips nav and footer, and can emit RAG chunks plus llms.txt. Pay $0.001 per page converted. Failed, blocked and empty pages are free.

- **URL**: https://apify.com/heyiambk/docs-to-markdown.md
- **Developed by:** [Tan Boon Kwee](https://apify.com/heyiambk) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 pages

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Docs to Markdown: Crawl Any Docs Site for LLM & RAG

**Docs to Markdown** turns a documentation site into clean, LLM-ready Markdown. Give it a docs URL. It finds pages through `sitemap.xml` and in-scope links, keeps the article body, and returns GitHub-flavoured Markdown with the navigation, footer and other chrome removed.

The Actor is **HTTP only**. It does not run a browser and it does not need an API key. You can use the output in a RAG index, an AI agent, a knowledge base, or as a local Markdown mirror of a docs site. Optional RAG chunks and `llms.txt` / `llms-full.txt` files are included in the same run.

Failed, blocked, redirected-out-of-scope, duplicate and near-empty pages are not charged.

### What can I use Docs to Markdown for?

- **RAG and vector-store ingestion:** crawl a product's docs and load the Markdown or the heading-path chunks into LangChain, LlamaIndex, or any other store you already use.
- **AI-agent context:** give an agent a current copy of a framework's or vendor's documentation instead of hoping the model remembers an old version.
- **llms.txt for your own docs:** generate an `llms.txt` index and an `llms-full.txt` bundle that you can host or attach to a chat.
- **A local Markdown mirror:** keep a dated snapshot of a docs site for review, search, or offline work.
- **Scheduled docs watch:** run the Actor daily or weekly so a pipeline always has a fresh corpus. Combine it with a webhook to start the next step when the run finishes.

It is aimed at documentation, help centres and other article-style sites that return HTML over HTTP (Docusaurus, MkDocs, Sphinx, GitBook, Mintlify and similar). Sites that render their content only in the browser will come back thin or empty; those pages are not charged.

### How to crawl a docs site to Markdown

1. Paste one or more **docs URLs**, for example `https://docs.python.org/3/tutorial/`.
2. Set **Max pages** to a small number for the first run (the prefill is 3). Raise it when you are happy with the output.
3. Leave **Stay under the start path** on if you want `/guide/` to stay in `/guide/` and not wander into `/blog/`.
4. Leave **Use sitemap.xml** and **Respect robots.txt** on unless you have a reason to turn them off.
5. Click **Start**. Download the dataset as JSON, CSV or Excel, or fetch `llms.txt` and `llms-full.txt` from the key-value store.

### Input

| Field | Meaning |
|---|---|
| Docs URLs | One or more documentation start URLs. The crawl stays on the same host and, by default, under the same path prefix. |
| Max pages | Cap on successfully converted (and charged) pages. Prefill is 3, so the first run and Apify's daily test stay small. |
| Stay under the start path | On by default. |
| Use sitemap.xml | On by default. The Actor reads `sitemap.xml` (and sitemap indexes) first, then follows in-scope links if it still needs more pages. |
| Respect robots.txt | On by default. Disallowed paths are skipped and not charged. |
| Content CSS selector | Optional. If set, only this part of the page is converted. Otherwise common docs containers are tried (`article`, `main`, `.theme-doc-markdown`, and similar). |
| RAG chunks / chunk size | Optional paragraph splits with a heading path, ready for embeddings. On by default, at 2,000 characters. |
| Write llms.txt | On by default. Writes an index and a combined Markdown file to the key-value store, at no extra charge. |

#### Input example

```json
{
  "startUrls": ["https://docs.python.org/3/tutorial/"],
  "maxPages": 50,
  "pathPrefixOnly": true,
  "useSitemap": true,
  "respectRobotsTxt": true,
  "includeChunks": true,
  "chunkSize": 2000,
  "includeLlmsTxt": true
}
```

A first test can use a single page URL and `"maxPages": 3`.

### Output

One dataset row per converted page:

| Field | Meaning |
|---|---|
| `url` | Final URL after redirects |
| `title` | Page title |
| `headings` | Outline of h1–h4 headings |
| `headingCount` | Number of headings |
| `markdown` | Clean GitHub-flavoured Markdown of the article body |
| `wordCount` | Word count of the Markdown |
| `contentHash` | SHA-256 of the Markdown, used to skip duplicates in the same run |
| `chunks` | Optional RAG chunks, each with `headingPath`, `charCount` and `text` |
| `status` | `ok` for a converted page; `error` for a free error row |

The key-value store also holds `llms.txt` (a list of page titles and URLs) and `llms-full.txt` (every page's Markdown in one file, each under a title and a `Source:` line), when that option is on.

#### Output example

```json
{
  "url": "https://docs.python.org/3/tutorial/introduction.html",
  "title": "3. An Informal Introduction to Python",
  "headingCount": 6,
  "wordCount": 1840,
  "markdown": "# 3. An Informal Introduction to Python\n\nIn the following examples...",
  "contentHash": "b4c1…",
  "status": "ok",
  "chunks": [
    {
      "index": 0,
      "headingPath": "3. An Informal Introduction to Python",
      "charCount": 1720,
      "text": "In the following examples, input and output are distinguished..."
    }
  ]
}
```

### How much does it cost?

You pay **US$0.001 per page converted** (US$1 per 1,000 pages). That is the only event this Actor charges. Failed, empty, blocked, out-of-scope and duplicate pages are free. `llms.txt` and `llms-full.txt` are free. There is no AI cost and no API key to add.

Pricing examples:

- **Quick test:** 3 pages = **US$0.003**
- **A small guide:** 50 pages = **US$0.05**
- **A 300-page docs site:** **US$0.30** once
- **A weekly refresh of 300 pages:** about **US$1.20 a month**

Apify also charges a tiny start fee per run (a fraction of a cent, based on memory). Set **max cost per run** in the run options if you want a hard cap; the Actor stops when the charge limit is reached. Compute for a small HTTP crawl is covered by the per-page price on ordinary docs sites.

### Schedule and webhook recipes

**Daily or weekly refresh.** In Console, open the Actor → Schedules → Create. Use the same input as a full crawl (your docs URL and a `maxPages` high enough for the whole site). A daily run of a 300-page site is about US$0.30 a day only if every page is converted again; you still only pay for pages that succeed.

**Webhook into your pipeline.** On the Actor or the task, add a webhook for the `SUCCEEDED` event and point it at your own URL (or at Make, Zapier, n8n, or a Cloudflare Worker). When the run finishes, your hook receives the run id. Fetch the dataset from `https://api.apify.com/v2/actor-runs/RUN_ID/dataset/items` and the files from the run's key-value store (`llms.txt`, `llms-full.txt`). That is enough to push a fresh corpus into a vector store without babysitting the run.

**Google Sheets or a bucket.** After a scheduled run, use an integration or a small script to write the dataset (URL, title, Markdown, word count) to a sheet, an S3/R2 bucket, or Git. The dataset export is JSON, CSV or Excel.

**Start from an API or MCP call.** Developers can start a run with the Apify API (`POST /v2/acts/heyiambk~docs-to-markdown/runs`) or from the Apify MCP server. Pass the same JSON input as in the Console. Use `waitForFinish` only for small `maxPages` values; for a large site, start the run and collect the results from the webhook.

### FAQ

**Does this work on any website?** It is built for documentation and help-centre pages that return HTML over HTTP. It is not a general JavaScript browser crawler, and it does not log in.

**Will it crawl the whole domain?** Not by default. It stays on the same host and under the start URL's path prefix, so a start URL of `https://docs.example.com/guide/` will not follow links into `/blog/`.

**What about PDFs, Word files or login walls?** Not in this version. Linked PDFs and pages behind a login are skipped or come back as free error rows.

**What if a page is JavaScript-only?** The Actor will likely return little or no text. That page is not charged. Try a content selector only if the HTML already contains the article. A browser-based crawler is a better fit for pages that never send the body over HTTP.

**Does it respect robots.txt?** Yes, by default. You can turn that off, but you should only do so on sites you own or have permission to crawl.

**How do I keep a run cheap while I test?** Set **Max pages** to 3 (the prefill) or even 1. Check the Markdown, then raise the cap.

**Can I crawl several docs sites in one run?** Yes. Add more start URLs. The `maxPages` cap applies to the whole run, and each start URL keeps its own host and path scope.

**Are there duplicates if the same article appears under two URLs?** The Actor skips a page in the same run when the Markdown `contentHash` has already been seen. Those skipped pages are not charged.

**Do I need an API key or a proxy?** No. Pages are fetched over ordinary HTTP from the Actor's server. If a site blocks datacenter IPs, that page will fail and stay free.

**How do I get one file for an LLM?** Turn on **Write llms.txt and llms-full.txt** (the default) and download `llms-full.txt` from the key-value store. Or concatenate the `markdown` field from the dataset yourself.

**What happens if I omit the start URL?** The Actor writes a free error row, sets a status message, and exits successfully. It does not fail the run. Apify's daily Store test uses the prefilled docs URL and a 3-page cap, so that path is the one that must keep working.

### Built by BATT Studio

This Actor is part of a small set of pay-per-event tools on the Apify Store under [heyiambk](https://apify.com/heyiambk). If something in the Markdown looks wrong for a particular docs theme, open an issue on the Actor page with the start URL and a short note.

# Actor input Schema

## `startUrls` (type: `array`):

One or more documentation URLs. The crawl stays on the same host and, by default, under the same path prefix.

## `maxPages` (type: `integer`):

Stop after this many successfully converted pages (and charges). Prefill is 3, for a cheap first run and a fast Store test.

## `pathPrefixOnly` (type: `boolean`):

If on, https://docs.example.com/guide/ will not follow links into /blog/.

## `useSitemap` (type: `boolean`):

Read sitemap.xml (and sitemap indexes) first, then follow in-scope links if more pages are needed.

## `respectRobotsTxt` (type: `boolean`):

Skip disallowed paths. On by default.

## `contentSelector` (type: `string`):

If set, only this selector is converted. Otherwise common docs containers are tried (article, main, .theme-doc-markdown, and similar).

## `includeChunks` (type: `boolean`):

Also split the Markdown into paragraph chunks with a heading path.

## `chunkSize` (type: `integer`):

Target character length per chunk when RAG chunks are on.

## `includeLlmsTxt` (type: `boolean`):

Save an index (llms.txt) and the combined Markdown (llms-full.txt) in the key-value store. Free.

## Actor input object example

```json
{
  "startUrls": [
    "https://docs.python.org/3/tutorial/introduction.html"
  ],
  "maxPages": 3,
  "pathPrefixOnly": true,
  "useSitemap": true,
  "respectRobotsTxt": true,
  "contentSelector": "",
  "includeChunks": true,
  "chunkSize": 2000,
  "includeLlmsTxt": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        "https://docs.python.org/3/tutorial/introduction.html"
    ],
    "maxPages": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("heyiambk/docs-to-markdown").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "startUrls": ["https://docs.python.org/3/tutorial/introduction.html"],
    "maxPages": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("heyiambk/docs-to-markdown").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    "https://docs.python.org/3/tutorial/introduction.html"
  ],
  "maxPages": 3
}' |
apify call heyiambk/docs-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,heyiambk/docs-to-markdown"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/F5a0sOhiuj8Pi2R0N/builds/GBAvgEVIQNZrNZpK7/openapi.json
