# Wikimedia Commons Category Hierarchy Scraper (`parseforge/wikimedia-commons-category-scraper`) Actor

Recursively scrapes Wikimedia Commons category trees from a start category. Returns parent-child relationships with page IDs and namespaces for building taxonomies or knowledge graphs.

- **URL**: https://apify.com/parseforge/wikimedia-commons-category-scraper.md
- **Developed by:** [ParseForge](https://apify.com/parseforge) (community)
- **Categories:** Other, AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.62 / 1,000 results

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?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

[![ParseForge](https://raw.githubusercontent.com/ParseForge/apify-assets/main/banner.jpg)](https://apify.com/parseforge?fpr=vmoqkp)

### Wikimedia Commons Category Hierarchy Scraper

**Scrape the Wikimedia Commons category hierarchy from any starting category, up to 10 levels deep.** Extract every subcategory title, page ID, and namespace, and reconstruct the full tree structure. Export to CSV, JSON, Excel, or XML.

Wikimedia Commons holds millions of freely licensed media files, organized across a large category tree. Manually navigating or mapping this hierarchy is slow and impractical. This Actor queries the official Wikimedia API to recursively extract category structures, giving you a clean dataset of parent-child relationships without writing a script.

| Who uses it | What they scrape Wikimedia Commons for |
|---|---|
| Digital archivists | Mapping the organizational structure of a public domain media collection. |
| Data scientists | Building a knowledge graph or taxonomy from Wikimedia Commons category relationships. |
| SEO analysts | Understanding how a large media repository categorizes topics for content strategy. |
| Researchers | Analyzing the distribution and depth of categories within a specific domain. |

### What it does

This Actor collects Wikimedia Commons subcategory titles and IDs from a starting category, recursively traversing the tree up to a specified depth, and returns each category relationship as a flat row.

- **Recursive tree traversal:** Start from any category and drill down through multiple levels of subcategories.
- **Configurable depth limit:** Control how deep the scraper goes, from a single level of children up to 10 levels.
- **Structured output:** Each row captures a parent category, its child subcategory, page ID, and namespace.

Results export to CSV, JSON, Excel, or XML, or straight from the API.

### What you can do with Wikimedia Commons data

**Map a media collection's structure.**

A digital archivist starts from 'Category:Photographs by topic' and extracts the full subcategory tree to understand how millions of images are organized.

**Build a training taxonomy.**

A machine learning engineer scrapes the category hierarchy under 'Category:Animals' to create a labeled dataset for hierarchical classification models.

**Audit category coverage.**

An SEO analyst extracts the subcategories of 'Category:Diagrams' to identify content gaps and plan new visual assets for a website.

### Why choose this scraper

| | What you get |
|---|---|
| **Official API access** | Reads directly from the public Wikimedia API with no authentication or API key required. |
| **Recursive extraction** | Automatically follows subcategory links to build a complete hierarchy from your chosen root. |
| **Clean relational output** | Returns parent-child pairs ready to import into graph databases or taxonomy tools. |

### What a Wikimedia Commons record looks like

Every record returns as one flat JSON row. Here is a real one from a run:

```json
{
 "pageid": 198793313,
 "ns": 14,
 "title": "Category:Categories by former function",
 "depth": 1,
 "parentTitle": "Category:Categories",
 "scrapedAt": "2026-09-04T00:45:59.430Z"
}
```

Every value above comes from a real run. A field a record does not have comes back as `null`.

### Configure the run

Drive the Actor by providing a single start category title, and set the maximum recursion depth to control how far down the tree it traverses. The Input tab lists every parameter.

A first run with the defaults:

```json
{
 "startCategory": "Category:Categories",
 "maxDepth": 2,
 "maxItems": 10
}
```

A larger pull:

```json
{
 "startCategory": "Category:Categories",
 "maxDepth": 2,
 "maxItems": 200
}
```

### Free users

Free-plan runs return up to 10 results as a preview. [Upgrade your Apify plan](https://console.apify.com/sign-up?fpr=vmoqkp) to collect up to 1,000,000 results per run.

### Run it

1. [Create a free Apify account](https://console.apify.com/sign-up?fpr=vmoqkp).
2. Open the [Wikimedia Commons Category Hierarchy Scraper](https://apify.com/parseforge/wikimedia-commons-category-scraper?fpr=vmoqkp).
3. Set your inputs and any filters, then click **Start**.
4. Export the results as CSV, Excel, JSON, or XML from the **Dataset** tab.

Run it programmatically through the [Apify API](https://docs.apify.com/api/v2) (`run-sync-get-dataset-items`) or the [ApifyClient](https://docs.apify.com/api/client/js) for JavaScript and Python.

### Use with AI agents (MCP)

Give an AI agent live access to Wikimedia Commons through the Model Context Protocol. Add the Actor to Claude, Cursor, or any MCP client:

```bash
claude mcp add --transport http apify "https://mcp.apify.com?tools=parseforge/wikimedia-commons-category-scraper"
```

Then prompt it in plain language to run the scraper and read back the results.

### Troubleshooting

**Why am I getting no results?**

Check that your start category title includes the exact 'Category:' prefix and matches an existing category on Wikimedia Commons. Also verify that the category contains subcategories; some leaf categories have none.

**The run is taking too long or timing out.**

Large category trees can take time to traverse. Reduce the maxDepth setting to limit how many levels the Actor follows, or lower the maxItems count to stop after a certain number of results.

**I see duplicate rows in my output.**

A subcategory can belong to multiple parent categories on Wikimedia Commons. The Actor records each parent-child relationship it finds, which may result in the same child appearing under different parents. This reflects the real category structure.

**The scraper stopped before reaching the maxDepth I set.**

The Actor respects the maxItems limit first. If it reaches the maximum number of items before exhausting the depth, it will stop. Increase the maxItems value to allow deeper traversal.

### FAQ

| Question | Answer |
|---|---|
| Do I need a Wikimedia account or API key to use this scraper? | No. The Actor uses the public, unauthenticated Wikimedia API, so no login, account, or API key is required. |
| How many levels of subcategories can I scrape? | You can set the maximum recursion depth from 1 up to 10. A depth of 1 returns only the direct children of your start category, while higher values traverse deeper into the tree. |
| What format is the output data in? | The dataset is returned as a flat table with parent and child category information. You can export it in CSV, JSON, Excel, or XML formats from the Apify platform. |
| Can I start from any Wikimedia Commons category? | Yes. Provide the full category title including the 'Category:' prefix, such as 'Category:Cities' or 'Category:Paintings', and the Actor will begin traversal from there. |
| Does this scraper download the actual media files? | No. This Actor extracts only the category hierarchy metadata, such as titles and IDs. It does not download images, videos, or other media files. |
| How is the category hierarchy represented in the output? | Each row represents a parent-child relationship between two categories, along with the child's page ID and namespace. You can reconstruct the full tree from these pairs. |
| Is there a limit to how many categories I can scrape? | Free users are limited to a preview of 10 items. Paid users can scrape up to 1,000,000 items per run, which is sufficient for very large category trees. |
| What is the 'namespace' field in the results? | The namespace indicates the type of page. For categories, this is typically 14. It helps you distinguish categories from other page types that might appear in the results. |

### Related actors

Browse the full [ParseForge collection](https://apify.com/parseforge?fpr=vmoqkp) for more scrapers.

🆘 **Need help?** Email parseforge@protonmail.com with your run ID, your input, and what you expected.

### Pricing

This Actor uses **pay-per-result** pricing: **$0.004 per result** collected. You are billed only for the results you receive, so a run that returns nothing costs nothing.

⚠️ **Disclaimer.** This Actor is unofficial and is not affiliated with, endorsed by, or sponsored by Wikimedia Foundation, Inc. It collects only publicly available data. You are responsible for using the collected data in compliance with the source's terms of service and applicable data-protection laws, including GDPR, CCPA, and PIPL. Do not use it to collect personal data unlawfully.

# Actor input Schema

## `startCategory` (type: `string`):

The full title of the Wikimedia Commons category to start from, including the 'Category:' prefix. For example, 'Category:Categories' to get the top-level category tree.

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

How many levels of subcategories to traverse. A value of 1 returns only direct children of the start category. Higher values build a deeper hierarchy.

## `maxItems` (type: `integer`):

Free users: Limited to 10 items (preview). Paid users: Optional, max 1,000,000

## Actor input object example

```json
{
  "startCategory": "Category:Categories",
  "maxDepth": 2,
  "maxItems": 10
}
```

# Actor output Schema

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

Complete dataset of all scraped records.

# 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 = {
    "startCategory": "Category:Categories",
    "maxDepth": 2,
    "maxItems": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("parseforge/wikimedia-commons-category-scraper").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 = {
    "startCategory": "Category:Categories",
    "maxDepth": 2,
    "maxItems": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("parseforge/wikimedia-commons-category-scraper").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 '{
  "startCategory": "Category:Categories",
  "maxDepth": 2,
  "maxItems": 10
}' |
apify call parseforge/wikimedia-commons-category-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,parseforge/wikimedia-commons-category-scraper"
        }
    }
}

```

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/kPbSOETqHMdM15kXY/builds/WZJjgcksBUvHpTump/openapi.json
