# AI Website to Clean Markdown & RAG Chunks Scraper (`narwal/ai-website-to-markdown-rag-scraper`) Actor

Convert any bloated webpage or JS-heavy SPA into clean Markdown, JSON, and RAG-ready chunks. Slash LLM token costs by up to 90%.

- **URL**: https://apify.com/narwal/ai-website-to-markdown-rag-scraper.md
- **Developed by:** [Tech Developer](https://apify.com/narwal) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.60 / 1,000 json results

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

## AI Website to Clean Markdown & JSON Scraper (RAG Ready)

Convert noisy, bloated web pages into clean, structured **Markdown (`.md`)**, **JSON**, and **context-aware RAG chunks** in seconds. Built specifically for AI Agents, LLM pipelines, and Vector Databases (Pinecone, Qdrant, Weaviate, Milvus).

By stripping out HTML boilerplate, navigation menus, ads, inline scripts, and CSS styling, this Actor reduces your raw webpage token footprint by **80% to 92%+**—slashing your OpenAI, Anthropic, and Gemini API costs while improving retrieval accuracy.

***

### Key Features for AI Developers

- **Hybrid Scraping Engine (`Auto` Mode):** Uses ultra-fast HTTP/2 requests (`httpx`) first for low compute cost and automatically falls back to a headless Chromium browser (`Playwright`) only when JavaScript/SPA rendering (React, Next.js, Vue) is required.
- **Massive LLM Token Savings:** Calculates and reports exact token reduction metrics (`raw_html_tokens` vs. `clean_output_tokens` and `tokens_saved_percentage`) on every scraped URL.
- **Built-In RAG Auto-Chunking:** Automatically splits extracted Markdown into semantic, overlapping character/token chunks so you can push embeddings directly into a Vector DB without extra preprocessing.
- **Rich Metadata Extraction:** Automatically extracts page `title`, `author`, `date`, `sitename`, `description`, `categories`, and `tags`.
- **Table & Link Preservation:** Converts complex HTML tables into clean GitHub-Flavored Markdown tables and preserves inline reference links.
- **Anti-Bot & Proxy Support:** Native integration with Apify Datacenter and Residential proxies.

***

### Input Parameters

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `startUrls` | Array | *Required* | List of website URLs to scrape and convert. |
| `scrapingMode` | String | `"auto"` | `"auto"` (HTTP + Playwright fallback), `"fast_http"` (fastest/cheapest), or `"playwright_browser"` (for JS-heavy SPAs). |
| `outputFormat` | String | `"markdown"` | Choose `"markdown"`, `"json"`, or `"both"`. |
| `includeLinks` | Boolean | `true` | Preserve hyperlinks inside extracted Markdown. |
| `includeImages` | Boolean | `false` | Include image URLs in Markdown output. |
| `includeTables` | Boolean | `true` | Convert HTML tables into clean Markdown tables. |
| `enableChunking` | Boolean | `true` | Split clean content into overlapping chunks for RAG & Vector DBs. |
| `chunkSize` | Integer | `1500` | Maximum character length per RAG chunk (~4 characters = 1 token). |
| `chunkOverlap` | Integer | `200` | Character overlap between consecutive chunks to preserve context. |
| `maxConcurrency` | Integer | `5` | Number of URLs to process in parallel. |
| `proxyConfiguration` | Object | Apify Proxy | Configure Apify Proxy to bypass rate limits and anti-bot protections. |

***

### Sample Output

Below is a real extraction result from `https://en.wikipedia.org/wiki/Retrieval-augmented_generation` demonstrating a **92.2% reduction in LLM tokens**:

````json
{
  "status": "success",
  "url": "[https://en.wikipedia.org/wiki/Retrieval-augmented_generation](https://en.wikipedia.org/wiki/Retrieval-augmented_generation)",
  "engine_used": "httpx",
  "title": "Retrieval-augmented generation",
  "metadata": {
    "title": "Retrieval-augmented generation",
    "author": "Contributors to Wikimedia projects",
    "date": "2026-10-01",
    "sitename": "Wikipedia",
    "description": "Technique for enhancing large language model accuracy with external data",
    "categories": [],
    "tags": []
  },
  "token_stats": {
    "raw_html_tokens": 68450,
    "clean_output_tokens": 5340,
    "tokens_saved": 63110,
    "tokens_saved_percentage": "92.2%"
  },
  "markdown": "# Retrieval-augmented generation\n\n**Retrieval-augmented generation** (**RAG**) is a technique that enables large language models (LLMs) to retrieve and incorporate new information...",
  "structured_json": null,
  "rag_chunks_count": 19,
  "rag_chunks": [
    {
      "chunk_id": 0,
      "char_length": 1184,
      "estimated_tokens": 296,
      "text": "# Retrieval-augmented generation\n\n**Retrieval-augmented generation** (**RAG**) is a technique that enables large language models (LLMs) to retrieve and incorporate new information..."
    }
  ],
  "scraped_at": "2026-10-22T03:55:00.000000+00:00"
}



# Actor input Schema

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

List of URLs to extract clean Markdown/JSON from.
## `scrapingMode` (type: `string`):

'auto' uses ultra-fast HTTP first and falls back to Playwright only if JS rendering is required. Saves Compute Units!
## `outputFormat` (type: `string`):

Choose the output structure for the extracted content.
## `includeLinks` (type: `boolean`):

Keep hyperlinks inside the extracted Markdown/text.
## `includeImages` (type: `boolean`):

Include Markdown image references in the output.
## `includeTables` (type: `boolean`):

Convert HTML tables into clean Markdown tables.
## `enableChunking` (type: `boolean`):

Split the clean text into smaller overlapping chunks ready for Vector Databases (Pinecone, Qdrant, Weaviate).
## `chunkSize` (type: `integer`):

Maximum character length per RAG chunk (~4 chars = 1 token).
## `chunkOverlap` (type: `integer`):

Character overlap between consecutive chunks to preserve context.
## `maxConcurrency` (type: `integer`):

Number of pages to process in parallel.
## `proxyConfiguration` (type: `object`):

Configure Apify Proxy to avoid IP blocks.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
    }
  ],
  "scrapingMode": "auto",
  "outputFormat": "markdown",
  "includeLinks": true,
  "includeImages": false,
  "includeTables": true,
  "enableChunking": true,
  "chunkSize": 1500,
  "chunkOverlap": 200,
  "maxConcurrency": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
````

# Actor output Schema

## `dataset` (type: `string`):

Default dataset containing the scraped web pages converted to clean Markdown and RAG chunks.

# 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://en.wikipedia.org/wiki/Retrieval-augmented_generation"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("narwal/ai-website-to-markdown-rag-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 = { "startUrls": [{ "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation" }] }

# Run the Actor and wait for it to finish
run = client.actor("narwal/ai-website-to-markdown-rag-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 '{
  "startUrls": [
    {
      "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
    }
  ]
}' |
apify call narwal/ai-website-to-markdown-rag-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,narwal/ai-website-to-markdown-rag-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/BQpdh8mjudJaj77pq/builds/poU7lmftIlAhX9qZ2/openapi.json
