# Website to RAG Markdown Crawler (`knotted_tussock/rag-markdown-crawler`) Actor

Crawl any website or docs site and export clean Markdown plus JSONL-style chunks for RAG, LLM apps, and AI agents.

- **URL**: https://apify.com/knotted\_tussock/rag-markdown-crawler.md
- **Developed by:** [Ralph T](https://apify.com/knotted_tussock) (community)
- **Categories:** AI, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Website to RAG Markdown Crawler

Crawl any website, documentation site, blog, or sitemap and export clean Markdown plus JSONL-style chunks for RAG, LLM apps, AI agents, and vector database pipelines.

### Quick start

Use a focused sitemap or docs URL first, keep `maxPages` low, inspect the RAG chunks view, then scale up:

```json
{
  "startUrls": [{ "url": "https://docs.apify.com/sitemap.xml" }],
  "maxPages": 5,
  "maxDepth": 0,
  "expandSitemaps": true,
  "includePatterns": ["^https://docs\\.apify\\.com/platform/actors"],
  "chunkSize": 1200,
  "chunkOverlap": 150,
  "includePageRecords": true
}
```

### What it does

- Starts from one or more web pages or `sitemap.xml` URLs.
- Expands sitemap indexes and sitemap URL sets into crawlable page URLs.
- Follows same-domain links up to a configurable depth.
- Removes navigation/footer/script/style noise.
- Converts HTML to clean Markdown.
- Emits both full-page records and smaller RAG chunk records.
- Adds estimated token counts for pages and chunks.
- Includes source URL, title, description, timestamps, character counts, token estimates, and chunk metadata.

### Best for

- Preparing documentation sites for RAG.
- Building AI chatbot or AI support-bot knowledge bases.
- Creating clean Markdown from help centers, blogs, changelogs, and product docs.
- Turning competitor docs/blogs into structured internal research data.
- Feeding LangChain, LlamaIndex, Supabase, Chroma, Pinecone, Qdrant, or custom vector pipelines.

### Input example

```json
{
  "startUrls": [{ "url": "https://docs.apify.com/sitemap.xml" }],
  "maxPages": 25,
  "maxDepth": 1,
  "expandSitemaps": true,
  "maxSitemapUrls": 5000,
  "includePatterns": ["^https://docs\\.apify\\.com/platform/actors"],
  "excludePatterns": ["/login", "/signup", "#"],
  "removeSelectors": ["nav", "footer", "script", "style", "noscript", "svg"],
  "chunkSize": 1200,
  "chunkOverlap": 150,
  "sameDomainOnly": true,
  "includePageRecords": true
}
```

### Output records

The Actor defines Apify dataset/output schemas so the Output tab has dedicated views for RAG chunks, full pages, and metadata. The default dataset contains two record types by default.

#### `page`

Full-page Markdown record:

```json
{
  "recordType": "page",
  "url": "https://example.com/",
  "requestedUrl": "https://example.com/",
  "title": "Example Domain",
  "description": "",
  "source": "sitemap",
  "sitemapUrl": "https://example.com/sitemap.xml",
  "markdown": "# Example Domain...",
  "charCount": 167,
  "estimatedTokenCount": 42,
  "tokenCountMethod": "approx_chars_per_4",
  "chunkCount": 1,
  "crawledAt": "2026-07-04T00:00:00.000Z"
}
```

#### `chunk`

RAG-ready chunk record:

```json
{
  "recordType": "chunk",
  "url": "https://example.com/",
  "title": "Example Domain",
  "chunkIndex": 0,
  "chunkCount": 1,
  "text": "# Example Domain...",
  "charCount": 167,
  "estimatedTokenCount": 42,
  "tokenCountMethod": "approx_chars_per_4",
  "metadata": {
    "source": "https://example.com/",
    "title": "Example Domain",
    "crawledAt": "2026-07-04T00:00:00.000Z",
    "sourceType": "sitemap",
    "sitemapUrl": "https://example.com/sitemap.xml"
  }
}
```

### Sitemap support

If a start URL looks like a sitemap, for example `https://example.com/sitemap.xml`, the Actor extracts URLs from `<loc>` entries and crawls the matching pages. Sitemap indexes are followed recursively. Use `includePatterns` and `excludePatterns` to focus large sitemaps before crawling.

### Token counts

The Actor includes an `estimatedTokenCount` field for each page and chunk using a fast `approx_chars_per_4` method. This is useful for budgeting embedding jobs and sizing RAG chunks. Treat it as an estimate rather than an exact model-specific tokenizer count.

### Example workflow

1. Enter a website URL or sitemap URL.
2. Set `maxPages` and `maxDepth` to control crawl size.
3. Use `includePatterns` / `excludePatterns` to keep the crawl focused.
4. Run the Actor.
5. Export `chunk` records as JSON/JSONL.
6. Load those chunks into your vector database or RAG pipeline.

### Notes

- This Actor is optimized for regular HTML pages, blogs, documentation sites, and help centers.
- JavaScript-heavy single-page apps may need a browser-based crawler variant.
- Keep `maxPages` low for first runs, inspect output, then scale up.
- Disable `includePageRecords` if you only want chunk records for embedding.

# Actor input Schema

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

Website pages or sitemap XML URLs to crawl. Sitemap URLs are expanded when Expand sitemaps is enabled.

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

Maximum number of HTML pages to crawl after sitemap expansion and link discovery.

## `maxDepth` (type: `integer`):

How far to follow same-domain links from non-sitemap start URLs. Sitemap-expanded URLs start at depth 0.

## `expandSitemaps` (type: `boolean`):

When a start URL looks like a sitemap XML file, extract page URLs from it and crawl those pages.

## `maxSitemapUrls` (type: `integer`):

Maximum number of URLs to read from sitemaps before maxPages is applied.

## `includePatterns` (type: `array`):

Optional regex patterns. If set, only matching URLs are crawled.

## `excludePatterns` (type: `array`):

Regex patterns for URLs to skip.

## `removeSelectors` (type: `array`):

Elements to remove before markdown conversion.

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

Approximate markdown characters per RAG chunk. Set 0 to disable chunks.

## `chunkOverlap` (type: `integer`):

Approximate overlapping characters between chunks.

## `sameDomainOnly` (type: `boolean`):

Only follow links on the same hostname as the current page or sitemap.

## `includePageRecords` (type: `boolean`):

Include full-page markdown records in addition to chunk records. Disable if you only want RAG chunks.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://docs.apify.com/sitemap.xml"
    }
  ],
  "maxPages": 25,
  "maxDepth": 1,
  "expandSitemaps": true,
  "maxSitemapUrls": 5000,
  "includePatterns": [],
  "excludePatterns": [
    "/login",
    "/signup",
    "#"
  ],
  "removeSelectors": [
    "nav",
    "footer",
    "script",
    "style",
    "noscript",
    "svg"
  ],
  "chunkSize": 1200,
  "chunkOverlap": 150,
  "sameDomainOnly": true,
  "includePageRecords": true
}
```

# Actor output Schema

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

All page and chunk records in the default dataset. Use the dataset views to inspect RAG chunks, full pages, or metadata.

## `ragChunks` (type: `string`):

Default dataset opened with the RAG chunks view selected for embedding/vector database workflows.

## `summary` (type: `string`):

Summary JSON containing pages saved, chunks saved, estimated token count, and sitemap queue counts.

# 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": [
        {
            "url": "https://docs.apify.com/sitemap.xml"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("knotted_tussock/rag-markdown-crawler").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": [{ "url": "https://docs.apify.com/sitemap.xml" }] }

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

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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": [
    {
      "url": "https://docs.apify.com/sitemap.xml"
    }
  ]
}' |
apify call knotted_tussock/rag-markdown-crawler --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=knotted_tussock/rag-markdown-crawler",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/sPFCFq7Ga107HkwpE/builds/iGTynulIVdSJwDpmA/openapi.json
