# Wikipedia Article + Pageviews API (`tidydata69/wikipedia-article-pageviews`) Actor

Fetch Wikipedia article metadata, plain extracts, and Wikimedia pageview stats via official MediaWiki Action API + Pageviews API. Never scrapes HTML.

- **URL**: https://apify.com/tidydata69/wikipedia-article-pageviews.md
- **Developed by:** [Bryce](https://apify.com/tidydata69) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 articles

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

## Wikipedia Article + Pageviews API

Fetch **Wikipedia article metadata and extracts** via the official **MediaWiki Action API**, plus optional **daily/monthly pageview counts** from the **Wikimedia Pageviews API**.

This Actor is an **API client only**. It does **not** scrape Wikipedia HTML. Wikimedia `robots.txt` disallows crawlers on `/w/` and `/api/` for HTML scraping — we only call the documented Action API (`action=query`) and the Pageviews REST API, with a descriptive User-Agent and polite serial rate limits (`maxlag=5`).

### What you get

#### Article rows (`type: "article"`)

| Field | Description |
| --- | --- |
| `title` / `pageid` / `url` | Canonical title, page id, full URL |
| `extract` | Plain intro summary (default `contentFormat=extracts`) |
| `wikitext` / `html` | Optional when `contentFormat` is `wikitext` or `html` |
| `lastrevid` / `touched` / `length` | Revision metadata from `prop=info` |
| `categories` | Optional category titles |
| `pageviewsTotal` / `pageviews` | Nested pageview summary when enabled |
| `missing` | `true` if the title does not exist |
| `attribution` | CC BY-SA attribution note |

#### Pageview rows (`type: "pageview"`)

One dataset item per day/month in range: `timestamp`, `views`, `project`, `granularity`, filters, and the same attribution note.

### Input

- **titles** (required) — article titles or full `https://{lang}.wikipedia.org/wiki/...` URLs
- **language** — default `en` when titles are not URLs
- **wiki** — optional Pageviews project override (`en.wikipedia`)
- **contentFormat** — `extracts` (default) | `wikitext` | `html` | `none`
- **includeCategories** — include `prop=categories`
- **includePageviews** — call Pageviews API (default true)
- **pageviewsStart** / **pageviewsEnd** — `YYYYMMDD` (default: last 7 days ending yesterday UTC)
- **pageviewsGranularity** — `daily` | `monthly`
- **pageviewsAccess** / **pageviewsAgent** — Pageviews dimensions (default `all-access` / `user`)
- **limit** — max articles
- **requestDelayMs** — min delay between HTTP calls (default 1100)

#### Example

```json
{
  "titles": ["Internet Archive", "Web scraping", "https://en.wikipedia.org/wiki/Apify"],
  "language": "en",
  "contentFormat": "extracts",
  "includePageviews": true,
  "pageviewsGranularity": "daily",
  "limit": 5
}
```

### How it works

1. Parses titles / Wikipedia URLs into `{title, language, wiki}`.
2. Calls `https://{lang}.wikipedia.org/w/api.php?action=query&...&maxlag=5` only (batched titles, serial HTTP).
3. Optionally calls `https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/...`.
4. Sends User-Agent: `tidydata69-wikipedia-article-pageviews (Apify Actor)`.
5. Writes article rows and pageview rows to the dataset with CC BY-SA attribution.

### Pricing (pay-per-event)

Intended Store pricing:

| Event | Price | Notes |
| --- | --- | --- |
| `apify-actor-start` | **$0.001** | Synthetic Actor start |
| `article` | **$0.001** | One article dataset row (`Actor.pushData(..., 'article')`) |
| `pageview-row` | **$0.0005** | One pageview dataset row (`Actor.pushData(..., 'pageview-row')`) |

Configure `pricingInfos` in Apify Console (or via API) when payout / billing info allows. Until then, the Actor still emits the named events so charges apply automatically once monetization is enabled.

### Licensing & attribution

Wikipedia text is available under **CC BY-SA**. Reusers must provide attribution. Each dataset item includes an `attribution` field pointing at CC BY-SA and Wikimedia Terms of Use. Pageview counts are from the public Wikimedia Pageviews API.

### Limitations & rules

- No HTML scraping of wikipedia.org article pages.
- Serial requests + `maxlag` + descriptive User-Agent per [API:Etiquette](https://www.mediawiki.org/wiki/API:Etiquette).
- Missing titles are returned with `missing: true` (still charged as an article lookup).
- Pageviews may 404 / return empty for brand-new or obscure titles / ranges.

### Use cases

- Enrich research datasets with Wikipedia summaries
- Track article popularity over a date range
- Build content pipelines without fragile HTML parsers

### Output

Open the run’s **Dataset** tab. Filter on `type` = `article` or `pageview`.

# Actor input Schema

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

One or more Wikipedia article titles (e.g. "Internet Archive") or full page URLs (e.g. https://en.wikipedia.org/wiki/Internet_Archive). Language/wiki is inferred from the URL when present; otherwise language/wiki inputs apply.

## `language` (type: `string`):

Default MediaWiki language subdomain when a title is not a full URL (e.g. en, de, fr). Ignored for absolute Wikipedia URLs that already include a language host.

## `wiki` (type: `string`):

Optional Wikimedia project for Pageviews (e.g. en.wikipedia). When empty, built as {language}.wikipedia. Rarely needed for non-Wikipedia sister projects.

## `contentFormat` (type: `string`):

What text to include from MediaWiki. extracts = plain intro/summary (recommended). wikitext = raw revision content. html = HTML extract (still via Action API, not page scrape). none = metadata only.

## `includeCategories` (type: `boolean`):

When true, include category titles from prop=categories (capped).

## `includePageviews` (type: `boolean`):

When true, call the Wikimedia Pageviews API for each found article and write pageview rows (plus a nested summary on the article record).

## `pageviewsStart` (type: `string`):

Inclusive start date for pageviews. Defaults to 7 days before pageviewsEnd (or before yesterday UTC).

## `pageviewsEnd` (type: `string`):

Inclusive end date for pageviews. Defaults to yesterday UTC (Pageviews data lags ~1 day).

## `pageviewsGranularity` (type: `string`):

daily or monthly aggregates from the Pageviews API.

## `pageviewsAccess` (type: `string`):

Pageviews access dimension.

## `pageviewsAgent` (type: `string`):

Pageviews agent dimension. Prefer user to exclude spiders.

## `limit` (type: `integer`):

Maximum articles to process from titles (after URL parsing / dedupe).

## `requestDelayMs` (type: `integer`):

Polite serial delay between MediaWiki / Pageviews HTTP calls (MediaWiki API:Etiquette). Default 1100 (~1 req/s).

## Actor input object example

```json
{
  "titles": [
    "Internet Archive",
    "Web scraping"
  ],
  "language": "en",
  "contentFormat": "extracts",
  "includeCategories": false,
  "includePageviews": true,
  "pageviewsGranularity": "daily",
  "pageviewsAccess": "all-access",
  "pageviewsAgent": "user",
  "limit": 5,
  "requestDelayMs": 1100
}
```

# Actor output Schema

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

MediaWiki article records (type=article) and optional Pageviews rows (type=pageview). Text is CC BY-SA — see attribution field.

# 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": [
        "Internet Archive",
        "Web scraping"
    ],
    "language": "en",
    "limit": 5,
    "requestDelayMs": 1100
};

// Run the Actor and wait for it to finish
const run = await client.actor("tidydata69/wikipedia-article-pageviews").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": [
        "Internet Archive",
        "Web scraping",
    ],
    "language": "en",
    "limit": 5,
    "requestDelayMs": 1100,
}

# Run the Actor and wait for it to finish
run = client.actor("tidydata69/wikipedia-article-pageviews").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": [
    "Internet Archive",
    "Web scraping"
  ],
  "language": "en",
  "limit": 5,
  "requestDelayMs": 1100
}' |
apify call tidydata69/wikipedia-article-pageviews --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,tidydata69/wikipedia-article-pageviews"
        }
    }
}
```

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/Slo6VGQJcsZxynW7K/builds/eth6uLr3LTduqyhla/openapi.json
