# MediaWiki Extractor - Wikipedia Text, Sections & Infobox (`cuantic_data/mediawiki-content-extractor`) Actor

Extracts plain text, table of contents (sections) and structured infobox data from Wikipedia pages in any language, using the official MediaWiki API. Great for LLM knowledge bases and research pipelines.

- **URL**: https://apify.com/cuantic\_data/mediawiki-content-extractor.md
- **Developed by:** [Cuantic Data](https://apify.com/cuantic_data) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 article extracteds

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

## MediaWiki Content Extractor — Wikipedia Text, Sections & Infobox

Extracts plain text, a table of contents (sections) and structured infobox
data from Wikipedia pages, in the language you ask for, via the official
MediaWiki API.

### What it does

- Plain-text article body (`extract`), with no wiki markup.
- Sections (table of contents) with their nesting level.
- Structured infobox as `{ key, value }` pairs, when the article has one and
  its template name starts with "Infobox" (see limitation below).
- Supports any Wikipedia language edition (`lang`, e.g. `en`, `es`, `pt`).
- If a page doesn't exist, it doesn't fail the whole run: it's reported as
  `found: false` in its own item.

### Who it's for

- Knowledge bases for AI agents / RAG.
- Research that needs structured data from many Wikipedia pages quickly
  (instead of copy-pasting by hand).

### Input

| Field | Type | Required | Description |
|---|---|---|---|
| `titles` | array of string | Yes | Exact page titles, maximum 50 per run. |
| `lang` | string | No (default `en`) | Wikipedia language code. |

```json
{ "titles": ["Argentina", "Chile"], "lang": "es" }
```

### Output

```json
{
  "title": "Argentina",
  "resolvedTitle": "Argentina",
  "lang": "es",
  "found": true,
  "extract": "Argentina, oficialmente...",
  "sections": [{ "level": 2, "title": "History" }, { "level": 2, "title": "Geography" }],
  "infobox": [{ "key": "capital", "value": "Buenos Aires" }],
  "sourceUrl": "https://es.wikipedia.org/wiki/Argentina"
}
```

### Pricing

Pay-per-event, provisional. Starting reference: USD 1.50 per 1,000 pages
extracted (`03-plan.md` §2).

### How to call it

```bash
curl "https://api.apify.com/v2/acts/cuantic-data~mediawiki-content-extractor/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"titles": ["Argentina", "Chile"], "lang": "es"}'
```

### Terms and limits

See [`TERMS.md`](./TERMS.md): the public, official MediaWiki API, with an
identifiable User-Agent and sequential (not parallel) requests, as
Wikimedia's policy requires.

**Known limitation:** the `infobox` field is only populated when the page's
template name starts with "Infobox" (works in English and many other
wikis). On wikis that use a translated template name (e.g. "Ficha de
persona" in Spanish), `infobox` comes back empty — plain text and sections
still work the same in any language.

### FAQ

**Why is the infobox empty when the article does have one?**
It's the limitation above: the template name doesn't start with "Infobox"
in that language/wiki. The rest of the data (text, sections) still works.

**Does it work with non-Wikipedia wikis?**
This version targets `{lang}.wikipedia.org`. Other MediaWiki wikis are
planned for a future version.

**Found a bug?**
Email `cuanticwindows@gmail.com` — we reply within 72 hours.

***

See `build/README.md` for how to run tests and publish this Actor.

# Actor input Schema

## `titles` (type: `array`):

Exact page names on Wikipedia (as they appear in the URL, with spaces instead of underscores). Maximum 50 per run.

## `lang` (type: `string`):

Wikipedia language code (e.g. en, es, pt, fr). Default: en.

## Actor input object example

```json
{
  "titles": [
    "Chile"
  ],
  "lang": "en"
}
```

# Actor output Schema

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

One item per requested title, with plain text, sections and infobox.

## `runSummary` (type: `string`):

Language, titles requested, how many were found and how many were not.

# 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 = {
    "titles": [
        "Chile"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("cuantic_data/mediawiki-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 = { "titles": ["Chile"] }

# Run the Actor and wait for it to finish
run = client.actor("cuantic_data/mediawiki-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 '{
  "titles": [
    "Chile"
  ]
}' |
apify call cuantic_data/mediawiki-content-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,cuantic_data/mediawiki-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/ferJlnB7laUpMWGzi/builds/yAoe8qxZ7MzORmjXg/openapi.json
