# Website Content Extractor (Text & Markdown for RAG) (`xtracto/website-content-extractor`) Actor

Turn any list of URLs into clean article text and markdown with metadata - title, author, dates, canonical URL and language. Reports which extraction strategy produced each row. Built for RAG and LLM pipelines.

- **URL**: https://apify.com/xtracto/website-content-extractor.md
- **Developed by:** [Farhan Febrian Nauval](https://apify.com/xtracto) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 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.
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

## Website Content Extractor — Clean Text & Markdown for RAG

Give it a list of URLs, get back the article text, the same content as markdown, and the page's
metadata: title, author, publication and modification dates, canonical URL, language, site name and
social image. Built for feeding RAG indexes and LLM pipelines, where boilerplate is noise and
structure is signal.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `urls` | array | *required* | Pages to extract. A bare domain works — `example.com` → `https://example.com` |
| `includeText` | boolean | `true` | The body as plain text |
| `includeMarkdown` | boolean | `true` | The body as markdown — headings, lists, links, code fences |
| `includeLinks` | boolean | `false` | Every link in the content, absolute, with anchor text |
| `maxCharacters` | integer | — | Truncate on a word boundary; `isTruncated` records it |

### Output

```jsonc
{
  "_input": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation",
  "_source": "S1-html",
  "_scrapedAt": "2026-09-12T12:41:07Z",
  "_extractedBy": "main-or-article",     // ← read this; see below

  "url": "…", "finalUrl": "…", "redirected": false,
  "title": "Retrieval-augmented generation - Wikipedia",
  "description": "…",
  "canonicalUrl": "…",
  "language": "en",
  "siteName": "Wikipedia",
  "author": "Contributors to Wikimedia projects",
  "publishedDate": "2023-11-05T13:19:20Z",
  "modifiedDate": "…",
  "imageUrl": "…",
  "isNoIndex": false,

  "wordCount": 2286, "charCount": 15420, "isTruncated": false,
  "text": "From Wikipedia, the free encyclopedia\n\nRetrieval-augmented generation (RAG) is…",
  "markdown": "From Wikipedia…\n\n**Retrieval-augmented generation** (**RAG**) is…"
}
```

### `_extractedBy` is the field that matters

Four strategies are tried in order, best evidence first, and **every row says which one won**:

| `_extractedBy` | What it means | Trust |
|---|---|---|
| `jsonld-article` | The publisher's own `articleBody` from schema.org JSON-LD | Highest — no guessing |
| `main-or-article` | A single `<main>` or `<article>` element | High |
| `densest-block` | The longest text block after boilerplate removal, scored by text length over link density | Good, but a guess |
| `body-minus-chrome` | `<body>` with navigation, headers, footers and banners stripped | Last resort |

That distinction is not cosmetic. On a badly built page, the bottom two strategies can return a
sidebar. If you are indexing at scale, filter on `_extractedBy` and treat a low `wordCount` from
`body-minus-chrome` as suspect.

A worked example from the test run: `federalregister.gov` returned a page titled *"Request Access"*
with 159 words — a bot-block notice, faithfully extracted. Nothing errored, because nothing failed;
the site simply served that. **A generic extractor cannot know every block page, so the signals it
gives you are `_extractedBy`, `wordCount` and missing metadata.** (Their *API*, incidentally, is
wide open — the block is on the website only.)

### What the markdown keeps, and why text is derived from it

Markdown preserves headings, bold and italic, links with their targets, images as `![alt](src)`,
ordered and unordered lists with nesting, blockquotes, horizontal rules and **code fences with their
indentation intact** — indentation is content in a code block, not formatting.

Plain text is then derived by stripping the markdown syntax, rather than read separately from the
DOM. Reading the DOM with a newline separator puts a break between every inline element: Wikipedia's
opening sentence comes out as `(\nRAG\n) is a technique`. Deriving from markdown keeps paragraphs
whole and guarantees both outputs describe the same content.

Tables degrade to their text on purpose. A table rendered as pipes that do not line up is worse for
a retrieval index than the same table as sentences.

### Errors

Every URL produces exactly one row, so a join against your input list stays aligned.

| `_error` | Meaning |
|---|---|
| `invalid_input` | Not a usable URL |
| `not_found` | HTTP 404 or 410 |
| `not_html` | A 200 whose content-type is a PDF, image or archive — a real URL, useless here |
| `too_large` | The response exceeded 8 MB |
| `no_content` | Fetched, but no strategy found usable text — often a client-rendered shell |
| `blocked` | Every TLS profile was refused |
| `network_error` | Never reached the server |

`https://example.com` returns `no_content`, correctly: the page has one sentence, below the
200-character floor that separates prose from navigation.

One note on `invalid_input`: because the URL field uses Apify's request-list editor, the platform
validates the shape of each entry **before the run starts** — a malformed entry is rejected there
with `Input is not valid`, not turned into a dataset row. The actor still guards against it for
programmatic callers, but from the Console or the API you will see a rejected run rather than an
error row. That is the platform doing the right thing; it is documented here so the absence of such
rows is not mistaken for the check being missing.

If no page yields content, the run fails rather than reporting success over an empty dataset.

# Actor input Schema

## `urls` (type: `array`):

Pages to extract. A bare domain works — example.com becomes https://example.com.

## `includeText` (type: `boolean`):

The article body as plain text.

## `includeMarkdown` (type: `boolean`):

The article body as markdown, keeping headings, lists, links and code blocks. Usually the better input for chunking.

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

Every link found in the content, absolute, with its anchor text and whether it leaves the site.

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

Cut text and markdown to this many characters, on a word boundary. Leave empty to keep everything; isTruncated says whether a row was cut.

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

Recommended for anything at scale, and required for sites that block datacenter addresses.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://blog.apify.com/what-is-web-scraping/"
    },
    {
      "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
    }
  ],
  "includeText": true,
  "includeMarkdown": true,
  "includeLinks": false,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

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

One row per scraped record, stored in the run's default dataset.

# 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 = {
    "urls": [
        {
            "url": "https://blog.apify.com/what-is-web-scraping/"
        },
        {
            "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("xtracto/website-content-extractor").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 = { "urls": [
        { "url": "https://blog.apify.com/what-is-web-scraping/" },
        { "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation" },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("xtracto/website-content-extractor").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 '{
  "urls": [
    {
      "url": "https://blog.apify.com/what-is-web-scraping/"
    },
    {
      "url": "https://en.wikipedia.org/wiki/Retrieval-augmented_generation"
    }
  ]
}' |
apify call xtracto/website-content-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,xtracto/website-content-extractor"
        }
    }
}
```

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/U8tcFEOchUpZsuKNd/builds/euJQUeC6kSf1Vl0kf/openapi.json
