# Llm Ready Documentation Scraper (`direct_duty/llm-ready-documentation-scraper`) Actor

Developers and AI agents need to read documentation (e.g. Stripe Docs, Next.js Docs), but standard scrapers return noisy HTML that includes:
navigation bars
headers / footers
ads / cookie banners
This Actor must return pure content-only Markdown, suitable for vectorization and semantic search.

- **URL**: https://apify.com/direct_duty/llm-ready-documentation-scraper.md
- **Developed by:** [Sean](https://apify.com/direct_duty) (community)
- **Categories:** Developer tools, Agents
- **Security:** Limited permissions
- **Stats:** 28 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

## LLM-Ready Documentation Scraper

Crawl any documentation website and get **clean, formatted Markdown** perfect for LLMs and RAG (Retrieval-Augmented Generation) applications.

### 🎯 Problem

Developers and AI agents need to read documentation (Stripe Docs, Next.js Docs, etc.), but standard scrapers return messy HTML with navbars, footers, and ads. This Actor solves that by delivering pure, clean Markdown.

### ✨ Features

- **Clean Markdown Output**: Strips navigation, sidebars, footers, scripts, and ads
- **Smart Content Detection**: Automatically finds the main content area
- **Token Counting**: Each page includes token count for LLM context planning
- **Merge Mode**: Combine all pages into a single `full_documentation.md` file
- **Configurable Depth**: Control how deep to crawl
- **URL Filtering**: Include/exclude patterns using globs

### 📥 Input

| Field | Type | Description |
|-------|------|-------------|
| `startUrl` | String | The root URL of the documentation site |
| `maxDepth` | Number | Maximum link depth to crawl (default: 10) |
| `maxPages` | Number | Maximum pages to scrape (default: 100) |
| `includeGlobs` | Array | URL patterns to include |
| `excludeGlobs` | Array | URL patterns to exclude |
| `excludeElements` | String | CSS selectors to remove |
| `contentSelector` | String | CSS selector for main content |
| `mergeOutput` | Boolean | Combine all pages into one file |

### 📤 Output

Each page is stored in the dataset with:

```json
{
  "url": "https://docs.example.com/api/auth",
  "title": "Authentication",
  "markdown": "# Authentication\n\nThis guide covers...",
  "tokenCount": 1523,
  "scrapedAt": "2024-01-15T10:30:00.000Z"
}
```

When `mergeOutput` is enabled, a combined `full_documentation.md` is saved to the Key-Value Store.

### 🚀 Usage Examples

#### Crawl Stripe Docs

```json
{
  "startUrl": "https://stripe.com/docs/api",
  "maxPages": 50,
  "mergeOutput": true
}
```

#### Crawl with Custom Content Selector

```json
{
  "startUrl": "https://nextjs.org/docs",
  "contentSelector": ".docs-content",
  "excludeElements": "nav, footer, .sidebar, .carbon-ads",
  "maxDepth": 3
}
```

### 🔧 Technical Details

- Built with **TypeScript** and the **Apify SDK**
- Uses **CheerioCrawler** for fast HTML parsing
- **Turndown** library for HTML-to-Markdown conversion
- **gpt-tokenizer** for accurate token counting

### 📝 License

ISC

# Actor input Schema

## `startUrl` (type: `string`):

The root URL of the documentation site to crawl (e.g., https://docs.example.com/api).

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

Maximum link depth to crawl from the start URL. Leave empty for unlimited depth.

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

Maximum number of pages to scrape. Useful for limiting large documentation sites.

## `includeGlobs` (type: `array`):

Glob patterns for URLs to include (e.g., '**/docs/**'). Leave empty to include all URLs on the same domain.

## `excludeGlobs` (type: `array`):

Glob patterns for URLs to exclude (e.g., '**/changelog/**', '**/blog/**').

## `excludeElements` (type: `string`):

CSS selectors for elements to strip before converting to Markdown. Separate multiple selectors with commas.

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

CSS selector for the main content area. If not found, the entire body is used after removing excluded elements.

## `mergeOutput` (type: `boolean`):

Combine all scraped pages into a single 'full_documentation.md' file in the Key-Value Store.

## `includeMetadata` (type: `boolean`):

Add a YAML frontmatter header with URL, title, and timestamp to each Markdown page.

## Actor input object example

```json
{
  "startUrl": "https://crawlee.dev/docs/introduction",
  "maxDepth": 10,
  "maxPages": 100,
  "includeGlobs": [],
  "excludeGlobs": [
    "**/blog/**",
    "**/changelog/**",
    "**/api-reference/**"
  ],
  "excludeElements": "nav, footer, .sidebar, script, style, .ads, header, .navigation, .menu, .toc, .breadcrumb, .edit-page, .feedback, .newsletter, aside",
  "contentSelector": "main, article, .content, .documentation",
  "mergeOutput": true,
  "includeMetadata": true
}
```

# 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 = {
    "startUrl": "https://crawlee.dev/docs/introduction",
    "maxDepth": 10,
    "maxPages": 100,
    "includeGlobs": [],
    "excludeGlobs": [
        "**/blog/**",
        "**/changelog/**",
        "**/api-reference/**"
    ],
    "excludeElements": "nav, footer, .sidebar, script, style, .ads, header, .navigation, .menu, .toc, .breadcrumb, .edit-page, .feedback, .newsletter, aside",
    "contentSelector": "main, article, .content, .documentation",
    "mergeOutput": true,
    "includeMetadata": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("direct_duty/llm-ready-documentation-scraper").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 = {
    "startUrl": "https://crawlee.dev/docs/introduction",
    "maxDepth": 10,
    "maxPages": 100,
    "includeGlobs": [],
    "excludeGlobs": [
        "**/blog/**",
        "**/changelog/**",
        "**/api-reference/**",
    ],
    "excludeElements": "nav, footer, .sidebar, script, style, .ads, header, .navigation, .menu, .toc, .breadcrumb, .edit-page, .feedback, .newsletter, aside",
    "contentSelector": "main, article, .content, .documentation",
    "mergeOutput": True,
    "includeMetadata": True,
}

# Run the Actor and wait for it to finish
run = client.actor("direct_duty/llm-ready-documentation-scraper").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 '{
  "startUrl": "https://crawlee.dev/docs/introduction",
  "maxDepth": 10,
  "maxPages": 100,
  "includeGlobs": [],
  "excludeGlobs": [
    "**/blog/**",
    "**/changelog/**",
    "**/api-reference/**"
  ],
  "excludeElements": "nav, footer, .sidebar, script, style, .ads, header, .navigation, .menu, .toc, .breadcrumb, .edit-page, .feedback, .newsletter, aside",
  "contentSelector": "main, article, .content, .documentation",
  "mergeOutput": true,
  "includeMetadata": true
}' |
apify call direct_duty/llm-ready-documentation-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,direct_duty/llm-ready-documentation-scraper"
        }
    }
}
```

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/zGsDih4a2pvYXR5LU/builds/O8bCFK1zMiwj1RJ4o/openapi.json
