# Universal Webpage to Clean Markdown for AI & RAG (`knightwwang/universal-webpage-to-clean-markdown-for-ai-rag`) Actor

Convert any webpage or article into clean, distraction-free Markdown and metadata. Optimized for feeding LLMs, AI Agents, LangChain, and RAG pipelines while saving prompt tokens.

- **URL**: https://apify.com/knightwwang/universal-webpage-to-clean-markdown-for-ai-rag.md
- **Developed by:** [knightwwang Wang](https://apify.com/knightwwang) (community)
- **Stats:** 2 total users, 1 monthly users, 20.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

## Universal Webpage to Clean Markdown for AI / LLMs & RAG

Transform any webpage, documentation, news article, or blog post into **clean, distraction-free Markdown** optimized for **Large Language Models (LLMs), AI Agents, LangChain, LlamaIndex, and RAG pipelines**.

***

### ⚡ Why Use This Actor?

Raw HTML pages are bloated with navigation menus, sidebars, cookie banners, tracking scripts, and footer links. Feeding raw HTML into LLMs wastes thousands of expensive prompt tokens and degrades model reasoning.

This Actor solves that problem by:

- 🧹 **Stripping Clutter**: Uses Mozilla's proven Readability engine to isolate the core readable article and discard boilerplate HTML.
- 📝 **Clean Markdown Output**: Converts clean HTML into standard GitHub-flavored Markdown (headers, lists, tables, code blocks).
- 💰 **Saves LLM Tokens**: Includes an option to strip images and estimate token counts, reducing API costs by up to **70%**.
- 📊 **Structured Metadata**: Automatically extracts title, author, publish date, site name, and language.
- 🛡️ **Proxy Support**: Integrates with Apify Proxy to scrape sites protected by geoblocking or anti-bot protections.

***

### 🚀 Use Cases

- **RAG & Knowledge Base Ingestion**: Preprocess URLs into pristine Markdown chunks before embedding into vector databases (Pinecone, Qdrant, Chroma).
- **AI Agents & Web Browsing Tools**: Equip your LangChain or AutoGen agents with a tool that reads any webpage instantly.
- **Dataset Creation**: Build high-quality instruction or fine-tuning datasets from documentation and articles.
- **LLM Context Injection**: Feed clean web research directly into ChatGPT, Claude 3.5, Gemini 1.5, or open-source LLMs without blowing context limits.

***

### 📥 Input Parameters

| Parameter | Type | Required | Default | Description |
| :--- | :--- | :--- | :--- | :--- |
| `startUrls` | Array | **Yes** | `[]` | List of URLs you want to parse into Markdown. |
| `includeMetadata` | Boolean | No | `true` | Extract title, author, publish date, and token estimate. |
| `removeImages` | Boolean | No | `false` | Strip `![alt](url)` markdown tags to minimize token size. |
| `proxyConfiguration` | Object | No | `{ useApifyProxy: true }` | Apify Proxy settings for seamless scraping. |

***

### 📤 Output Format

The Actor stores results in Apify Dataset format (exportable as JSON, CSV, Excel, or NDJSON):

````json
{
  "url": "https://example.com/blog/ai-future",
  "metadata": {
    "title": "The Future of AI Agents in 2026",
    "byline": "Jane Doe",
    "excerpt": "A deep dive into how AI agents are reshaping software.",
    "siteName": "Tech Insights",
    "publishedTime": "2026-10-15T08:00:00Z",
    "language": "en",
    "characterCount": 4200,
    "estimatedTokens": 1050
  },
  "markdown": "# The Future of AI Agents in 2026\n\nAI agents are revolutionizing...\n\n- Point 1\n- Point 2\n\n```python\nprint('Hello AI')\n```",
  "scrapedAt": "2026-10-20T08:00:00.000Z"
}
````

***

### 🔗 How to Integrate via API

You can call this Actor directly from Python, Node.js, or curl inside your AI application:

#### Python (LangChain / LlamaIndex / OpenAI)

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_API_TOKEN")

run = client.actor("YOUR_USERNAME/web-to-clean-markdown-ai").call(
    run_input={
        "startUrls": [{"url": "https://en.wikipedia.org/wiki/Artificial_intelligence"}],
        "removeImages": True,
    }
)

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["markdown"])
```

# Actor input Schema

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

List of URLs you want to scrape and convert into clean Markdown for AI.

## `outputFormat` (type: `string`):

Choose between full markdown document, pre-chunked RAG format, or both.

## `chunkForRAG` (type: `boolean`):

Automatically split markdown into optimized chunks by semantic headers and token limit.

## `maxChunkTokens` (type: `integer`):

Target token limit per chunk (ideal for embeddings like text-embedding-3: 500-1000).

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

Extract title, author, publish date, description, and exact token counts.

## `removeImages` (type: `boolean`):

Strip markdown images (![alt](url)) to save LLM tokens.

## `removeLinks` (type: `boolean`):

Strip markdown URLs [text](url) -> text to further minimize prompt tokens.

## `proxyConfiguration` (type: `object`):

Use Apify Proxy to bypass geo-restrictions and anti-scraping.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://en.wikipedia.org/wiki/Artificial_intelligence"
    }
  ],
  "outputFormat": "markdown",
  "chunkForRAG": true,
  "maxChunkTokens": 800,
  "includeMetadata": true,
  "removeImages": false,
  "removeLinks": false,
  "proxyConfiguration": {
    "useApifyProxy": 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 = {
    "startUrls": [
        {
            "url": "https://en.wikipedia.org/wiki/Artificial_intelligence"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("knightwwang/universal-webpage-to-clean-markdown-for-ai-rag").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/Artificial_intelligence" }] }

# Run the Actor and wait for it to finish
run = client.actor("knightwwang/universal-webpage-to-clean-markdown-for-ai-rag").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/Artificial_intelligence"
    }
  ]
}' |
apify call knightwwang/universal-webpage-to-clean-markdown-for-ai-rag --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,knightwwang/universal-webpage-to-clean-markdown-for-ai-rag"
        }
    }
}
```

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/woIRj6GWb3GE7cFYh/builds/eSPE5YIfELuWFoKY9/openapi.json
