# Web Page to Markdown (LLM-ready) (`black-vikings/web-to-markdown`) Actor

Turn public web pages into clean, LLM-ready Markdown: main content only, GFM tables, word and token counts, heading outline and optional RAG chunks. Plain HTTP, robots.txt obeyed, and you only pay for pages that convert.

- **URL**: https://apify.com/black-vikings/web-to-markdown.md
- **Developed by:** [Black Vikings](https://apify.com/black-vikings) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.60 / 1,000 converted pages

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Web Page to Markdown (LLM-ready)

Turn public web pages into clean Markdown for LLMs, RAG pipelines and AI agents. The Actor fetches each page over plain HTTP, extracts the main content with Mozilla Readability, and converts it to tidy Markdown with GitHub tables. Each page comes with its title, description, language, word count, approximate token count, heading outline and, if you want, ready-made RAG chunks.

You pay only for pages that convert. Blocked, broken, duplicate and JavaScript-only pages are free.

### What you can do with it

- **Feed an LLM.** Give it a list of URLs and get back Markdown without menus, footers, cookie banners or scripts.
- **Build a RAG index.** Turn on chunking to get paragraph-aligned chunks of a chosen token size, with overlap.
- **Crawl a docs site or blog.** Follow same-site links up to a depth, or read the site's XML sitemap.
- **Control the content.** Keep only `main, article`, drop `.ads, #comments`, keep or drop links and images, cap the length.
- **Detect changes.** Each page has a `contentHash` (SHA-256 of the Markdown); compare it between runs.

### Input

| Field | Default | What it does |
|---|---|---|
| `startUrls` | (required) | Pages to convert. In sitemap mode, a site URL or a sitemap URL. |
| `mode` | `urls` | `urls`: only the start URLs. `crawl`: also follow links on the same site. `sitemap`: pages listed in the XML sitemaps (robots.txt `Sitemap:` lines, or `/sitemap.xml`). |
| `maxPages` | 50 | Maximum pages fetched in the run, start URLs included (up to 10,000). |
| `maxDepth` | 1 | Crawl mode: how many links away from a start URL to go. |
| `useReadability` | true | Main content only. Turn off to convert the whole body. |
| `includeSelectors` | none | Convert only elements matching these CSS selectors (overrides Readability). |
| `excludeSelectors` | none | Remove these elements first. |
| `keepLinks` | true | Keep links as `[text](url)`; off keeps only the text. |
| `keepImages` | false | Keep images as `![alt](url)`. |
| `includeLinks` | false | Add a `links` list with every link on the page. |
| `maxCharacters` | 0 | Cut the Markdown at a word boundary; 0 means no limit. |
| `chunking` | false | Add `chunks` for RAG. |
| `chunkSizeTokens` | 512 | Approximate maximum tokens per chunk. |
| `chunkOverlapTokens` | 64 | Approximate tokens repeated from the previous chunk (kept below half the chunk size). |

Example:

```json
{
  "startUrls": [{ "url": "https://en.wikipedia.org/wiki/Web_scraping" }],
  "mode": "urls",
  "chunking": true,
  "chunkSizeTokens": 512
}
```

### Output

One dataset item per converted page:

```json
{
  "url": "https://en.wikipedia.org/wiki/Web_scraping",
  "finalUrl": "https://en.wikipedia.org/wiki/Web_scraping",
  "statusCode": 200,
  "depth": 0,
  "title": "Web scraping",
  "description": "For broader coverage of this topic, see Data scraping.",
  "language": "en",
  "markdown": "# Web scraping\n\n**Web scraping**, **web harvesting**, or **web data extraction** is ...",
  "truncated": false,
  "originalCharacters": null,
  "omittedFields": [],
  "wordCount": 4017,
  "approxTokens": 10309,
  "headings": [{ "level": 1, "text": "Web scraping" }, { "level": 2, "text": "History" }],
  "chunks": [{ "index": 0, "text": "# Web scraping\n\n...", "approxTokens": 498 }],
  "links": null,
  "contentHash": "7a59b715...",
  "fetchedAt": "2026-11-24T10:00:00.000Z"
}
```

Apify stores at most about 9 MB per dataset item. For the rare page whose output would be larger, the Actor drops the `links` list first, then `chunks` (they repeat the Markdown), then truncates the Markdown; `omittedFields` lists what was dropped and `originalCharacters` gives the full length. The run never fails because of this.

`approxTokens` estimates tokens at about 4 characters per token, which is close for English text with GPT-style tokenizers; other languages and code may differ. `chunks` is `null` unless chunking is on, and `links` is `null` unless `includeLinks` is on.

Every run also saves a summary in the `OUTPUT` record of the key-value store:

```json
{
  "mode": "crawl",
  "totals": { "startUrls": 1, "pagesConverted": 29, "pagesFailed": 1, "duplicatesSkipped": 1, "linksSkippedByRobots": 16, "convertedButNotStoredDueToLimit": 0, "pagesNotFetched": 0 },
  "failuresByReason": { "needs_browser": 1 },
  "failures": [{ "url": "https://example.com/app", "reason": "needs_browser", "message": "Only 2 words without JavaScript; ...", "statusCode": 200 }],
  "chargeLimitReached": false
}
```

Failure reasons (never charged): `needs_browser` (the content is rendered by JavaScript), `no_content`, `http_error`, `network_error`, `not_html`, `too_large` (over 5 MB), `blocked_by_robots`, `private_address`, `conversion_error`, `sitemap_error`.

### Pricing

Pay per event: $1.00 per 1,000 converted pages (event `page`) on the Free plan, $0.80 on Starter, $0.70 on Scale and $0.60 on Business. Failed pages, pages that need a browser and duplicate pages are free.

You are charged once for each page saved to the dataset. Failed pages, pages blocked by robots.txt, JavaScript-only pages and pages whose Markdown is identical to one already delivered in the run cost nothing. The run respects your maximum charge per run: it stops fetching when the limit is reached, keeps what it saved, and reports the rest in `OUTPUT`.

### When does a run fail?

- **Fails:** invalid input, no page could be converted, or the maximum charge does not cover a single page. Nothing is charged.
- **Succeeds with a warning:** some pages failed, or `maxPages` or the charge limit left pages out. The run status and `OUTPUT` list them.

If the platform migrates or restarts the run, it resumes from a checkpoint and never charges a delivered page twice.

### Legal and responsible use

- **You must have the right to use the content you convert.** You choose the URLs and are responsible for complying with each site's terms of service, copyright, database rights and privacy law (for example the GDPR). Respect the AI-usage preferences a site publishes, such as `Content-Signal: ai-train=no` in its robots.txt.
- The Actor fetches public pages only: no logins, cookies or paywalls, no CAPTCHA solving, no proxies or browser fingerprints to evade blocks.
- It obeys robots.txt (including `Crawl-delay`, capped at 10 seconds) and sends an honest User-Agent: `web-to-markdown/0.1 (Apify Actor; +https://apify.com/black-vikings/web-to-markdown; obeys robots.txt)`. If robots.txt cannot be fetched because of a server error, the site is treated as disallowed.
- Requests to one host are spaced at least 250 ms apart.
- Private, local and reserved network addresses cannot be fetched, also not through redirects or DNS names that resolve to them.
- Do not use it to collect personal data about private individuals.

### FAQ

**Why did a page fail as `needs_browser`?** Without JavaScript it showed fewer than 20 words, and it loads scripts, so its content is most likely built in the browser. This Actor uses plain HTTP to stay fast and cheap; use a browser-based Actor for such pages. You were not charged.

**The Markdown misses part of the page.** Readability keeps the main article. Turn off `useReadability` to keep the whole body, or name the parts you want in `includeSelectors`.

**How exact is `approxTokens`?** It is an estimate (characters divided by 4). Use your model's tokenizer when you need exact counts.

**Can I crawl a whole website?** Yes, with `mode: crawl` or `mode: sitemap`, up to 10,000 pages per run. Crawls stay on the start URL's host (`www.` and the bare domain count as the same site).

**Can it read PDFs?** No. Links to PDFs, images and other files are skipped in crawls, and such URLs fail as `not_html` (not charged).

**Can I convert pages behind a login?** No. Public pages only.

### Developer notes

- `npm test` runs unit tests and local HTTP-server tests (no internet). `npm run test:coverage` enforces 80%.
- `npm run health` converts stable public pages live (Wikipedia, MDN). A daily GitHub workflow runs it.
- Stack: Node 22, plain `fetch`, `linkedom` + `@mozilla/readability`, `turndown` + GFM tables, `robots-parser`.
- Pricing is configured in Apify Console: one pay-per-event event named `page` (mirrored in `.actor/pay_per_event.json`), with Store discount tiers per plan.

# Actor input Schema

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

Public web pages to convert. https:// is added when missing; duplicates are fetched once. In sitemap mode, give a site URL (its robots.txt Sitemap lines or /sitemap.xml are read) or a sitemap URL. Only use pages you have the right to use.

## `mode` (type: `string`):

urls: convert only the start URLs. crawl: also follow links to pages on the same site, up to Max depth. sitemap: convert the pages listed in the sites' XML sitemaps.

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

Maximum number of pages fetched in the run, start URLs included. Only successfully converted pages are charged.

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

How many links away from a start URL the crawl may go. 0 converts only the start URLs, 1 adds the pages they link to, and so on.

## `useReadability` (type: `boolean`):

Extract the main article with Mozilla Readability and drop navigation, footers and sidebars. Turn off to convert the whole page body.

## `includeSelectors` (type: `string`):

Convert only the elements matching these CSS selectors, e.g. "main, article .content". Overrides Main content only.

## `excludeSelectors` (type: `string`):

Remove elements matching these CSS selectors before conversion, e.g. ".ads, #comments, .newsletter".

## `keepLinks` (type: `boolean`):

Keep hyperlinks as [text](url). Turn off to keep only the link text (fewer tokens).

## `keepImages` (type: `boolean`):

Keep images as ![alt](url). Off by default to save tokens.

## `includeLinks` (type: `boolean`):

Add a links field with every link found on the page (URL and text).

## `maxCharacters` (type: `integer`):

Cut the Markdown to at most this many characters (at a word boundary). 0 means no limit.

## `chunking` (type: `boolean`):

Add a chunks field: the Markdown split on paragraph boundaries into pieces of about Chunk size tokens, for embeddings and retrieval.

## `chunkSizeTokens` (type: `integer`):

Approximate maximum tokens per chunk (about 4 characters per token).

## `chunkOverlapTokens` (type: `integer`):

Approximate tokens repeated from the end of the previous chunk. Must be below half the chunk size; larger values are lowered automatically (with a warning in the log).

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://en.wikipedia.org/wiki/Web_scraping"
    },
    {
      "url": "https://en.wikipedia.org/wiki/Markdown"
    }
  ],
  "mode": "urls",
  "maxPages": 50,
  "maxDepth": 1,
  "useReadability": true,
  "keepLinks": true,
  "keepImages": false,
  "includeLinks": false,
  "maxCharacters": 0,
  "chunking": false,
  "chunkSizeTokens": 512,
  "chunkOverlapTokens": 64
}
```

# Actor output Schema

## `pages` (type: `string`):

One item per converted page: Markdown, title, description, language, word and token counts, heading outline, optional chunks and links.

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

Totals, failures by reason (not charged) and whether the charge limit was reached.

# 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/Web_scraping"
        },
        {
            "url": "https://en.wikipedia.org/wiki/Markdown"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("black-vikings/web-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": [
        { "url": "https://en.wikipedia.org/wiki/Web_scraping" },
        { "url": "https://en.wikipedia.org/wiki/Markdown" },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("black-vikings/web-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": [
    {
      "url": "https://en.wikipedia.org/wiki/Web_scraping"
    },
    {
      "url": "https://en.wikipedia.org/wiki/Markdown"
    }
  ]
}' |
apify call black-vikings/web-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,black-vikings/web-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/JcArI7d8dYrG0PAbH/builds/B2VuaXggMBEArt37O/openapi.json
