# Sitemap Extractor — Recursive Crawl with lastmod & Priority (`axery/sitemap-extractor`) Actor

Recursively crawl any sitemap.xml or sitemap index into a flat list of URLs with lastmod, changefreq and priority — the fastest way to enumerate a site's pages.

- **URL**: https://apify.com/axery/sitemap-extractor.md
- **Developed by:** [Axery](https://apify.com/axery) (community)
- **Categories:** SEO tools, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 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

## Sitemap Extractor

Recursively crawls any `sitemap.xml` — including a sitemap index pointing at hundreds of child files — into a flat list of URLs. Over plain HTTP, no browser, no login: a sitemap is a file websites publish specifically so machines can enumerate their pages.

### Handles both sitemap shapes, and both compression states

The [sitemap protocol](https://www.sitemaps.org/protocol.html) defines two document types, and large sites almost always use both:

- **`<sitemapindex>`** — a list of child sitemap files. This Actor traverses it breadth-first, recursing up to 4 levels deep (some very large sites nest indexes inside indexes).
- **`<urlset>`** — the actual page list, each entry optionally carrying `lastmod`, `changefreq` and `priority`.

Either may be gzip-compressed (`sitemap.xml.gz`) per the spec. This Actor detects that from the response's own magic bytes rather than trusting the URL extension or the `Content-Type` header, since servers are inconsistent about both.

### What you get per URL

```json
{
  "url": "https://techcrunch.com/press-release/example/",
  "path": "/press-release/example/",
  "lastmod": "2026-08-22",
  "changefreq": null,
  "priority": null,
  "sitemap_url": "https://techcrunch.com/sitemap-page-1.xml"
}
```

`lastmod` is passed through exactly as the site writes it — some use a bare date, others full ISO-8601 with time. `sitemap_url` tells you which child file a URL came from, useful when a site splits its sitemap by section (`/blog/`, `/products/`) or by date.

### Filtering without extra requests

`urlContains` and `pathPrefix` filter client-side as the crawl streams in, so you can point this at a site's root sitemap index and pull out just `/blog/` or `/products/` without writing a separate crawler for each section.

### Input

| Field | Type | Notes |
|---|---|---|
| `startUrl` | string | A sitemap or sitemap index URL. Usually `/sitemap.xml` or `/sitemap_index.xml`, and referenced in `/robots.txt` if you need to find it. |
| `urlContains` | string | Keep only URLs containing this substring. |
| `pathPrefix` | string | Keep only URLs whose path starts with this. |
| `maxItems` | integer | Cap on URLs returned. `0` = unlimited. |
| `maxSitemaps` | integer | Cap on sitemap *files* fetched during traversal — independent of `maxItems`, since an index can have hundreds of children. |
| `proxyConfiguration` | object | Sitemaps have no anti-bot layer; leave this off unless a specific target needs it. |

### Known limits

- **50 MB uncompressed cap per file**, per the sitemap protocol's own limit — a compliant sitemap never exceeds this, so hitting it means the file is non-standard.
- **`lastmod` format varies by site** and is passed through unparsed rather than guessed at, so downstream code should handle both a bare date and a full timestamp.
- **Nested indexes stop at depth 4.** No real-world site has needed to go deeper in testing, but a pathological case would be truncated rather than looping forever.

### Local development

```bash
pip install -r requirements.txt
python test_local.py "https://apify.com/sitemap.xml" --max 20 --out sample_output.json
python test_local.py "https://techcrunch.com/sitemap_index.xml" --contains press-release --max 10
```

`sample_output.json` in this folder is real output from a live run, kept so the schema can be reviewed without running anything.

# Actor input Schema

## `startUrl` (type: `string`):

URL of a sitemap.xml or sitemap index. Most sites publish theirs at `/sitemap.xml` or `/sitemap_index.xml`, and it is usually referenced in `/robots.txt`.

## `urlContains` (type: `string`):

Keep only URLs containing this substring, e.g. `/blog/` to extract only blog posts from a site's combined sitemap.

## `pathPrefix` (type: `string`):

Keep only URLs whose path starts with this prefix, e.g. `/products/`.

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

Maximum URLs to return. Set to `0` for unlimited - reasonable for a small site, risky for a news site with millions of pages.

## `maxSitemaps` (type: `integer`):

Safety cap on how many sitemap *files* are fetched while traversing an index, independent of the URL limit above. Large sites split their sitemap into hundreds of files.

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

Apify Proxy settings. Sitemaps are ordinary static files with no anti-bot layer, so most sites need no proxy at all - leave this off unless a specific target requires it.

## Actor input object example

```json
{
  "startUrl": "https://apify.com/sitemap.xml",
  "urlContains": "/blog/",
  "pathPrefix": "/products/",
  "maxItems": 1000,
  "maxSitemaps": 200
}
```

# Actor output Schema

## `urls` (type: `string`):

One row per page URL: the URL itself, its path, and lastmod/changefreq/priority when the sitemap provides them.

## `coverage` (type: `string`):

How many sitemap files were traversed and how many URLs were returned, and any files that failed to fetch.

# 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 = {
    "startUrl": "https://apify.com/sitemap.xml",
    "maxItems": 1000
};

// Run the Actor and wait for it to finish
const run = await client.actor("axery/sitemap-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 = {
    "startUrl": "https://apify.com/sitemap.xml",
    "maxItems": 1000,
}

# Run the Actor and wait for it to finish
run = client.actor("axery/sitemap-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 '{
  "startUrl": "https://apify.com/sitemap.xml",
  "maxItems": 1000
}' |
apify call axery/sitemap-extractor --silent --output-dataset

```

## MCP server setup

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