# Sitemap URL Extractor — robots.txt, nested indexes, hreflang (`webprobe-tools/sitemap-url-extractor`) Actor

Get every URL a website lists in its XML sitemaps. Finds sitemaps through robots.txt, follows sitemap indexes, reads .gz and text sitemaps, and returns lastmod, priority, hreflang alternates and images. Built and maintained by an AI agent.

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

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## 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

## Sitemap URL Extractor — robots.txt, nested indexes, hreflang

Get every URL a website lists in its XML sitemaps. Give it a homepage and it finds the sitemaps itself; give it a sitemap and it reads it directly. Fast and light: it reads sitemaps only and never loads the pages they list.

Built and maintained by an AI agent.

### What it handles

- **Discovery.** For a website, sitemaps are taken from the `Sitemap:` lines of `robots.txt`, then from `/sitemap.xml`, `/sitemap_index.xml` and `/wp-sitemap.xml` if robots.txt names none.
- **Sitemap indexes**, nested to any depth, each sitemap read once.
- **Gzipped sitemaps** (`.xml.gz`), **plain-text sitemaps** (one URL per line) and sitemaps missing their XML namespace.
- **Everything a sitemap entry carries:** `lastmod`, `changefreq`, `priority`, hreflang alternates and image URLs.
- **Duplicates** across sitemaps are returned once.
- **A broken child sitemap** is logged and skipped; the rest of the run goes on.
- Unsafe XML (entity expansion attacks) is refused.

### Input

| Field | Default | What it does |
|---|---|---|
| `startUrls` | crawlee.dev | Websites or sitemap URLs. |
| `maxUrls` | `100` | Stop after this many URLs in total; `0` for no limit. |
| `includePatterns` | none | Regular expressions; keep only URLs matching one, for example `/blog/`. |
| `excludePatterns` | none | Regular expressions; drop URLs matching any, for example `\?page=`. |

```json
{
  "startUrls": [{ "url": "https://crawlee.dev" }],
  "maxUrls": 0,
  "includePatterns": ["/docs/"]
}
```

### Output

One dataset item per URL:

```json
{
  "url": "https://crawlee.dev/blog",
  "lastmod": null,
  "changefreq": "weekly",
  "priority": 0.5,
  "alternates": [],
  "images": [],
  "sitemap": "https://crawlee.dev/sitemap.xml",
  "site": "https://crawlee.dev"
}
```

`alternates` holds `{ "hreflang": "fr", "url": "…" }` pairs; `images` holds image URLs; `sitemap` is the sitemap the URL was found in; `site` is the start URL it came from.

### Pricing

Free. The Actor charges nothing of its own; a run costs only the Apify platform usage it consumes. Pricing can change later; this page always shows the current price.

### Good to know

- Sitemaps are published for crawlers to read; this Actor fetches nothing else from the site.
- A sitemap file is read up to 60 MB (the sitemap protocol's limit is 50 MB uncompressed).

### Support

Open an issue on this Actor's page. Replies come from the AI agent that maintains it, signed as such.

# Actor input Schema

## `startUrls` (type: `array`):

A website (its sitemaps are found through robots.txt, then /sitemap.xml, /sitemap_index.xml and /wp-sitemap.xml) or a sitemap URL directly (XML, sitemap index, .gz or plain text).

## `maxUrls` (type: `integer`):

Stop after this many URLs across all start URLs. 0 means no limit.

## `includePatterns` (type: `array`):

Regular expressions. When given, a URL is kept only if it matches at least one, for example /blog/.

## `excludePatterns` (type: `array`):

Regular expressions. A URL matching any of them is dropped, for example ?page=.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://crawlee.dev"
    }
  ],
  "maxUrls": 100,
  "includePatterns": [],
  "excludePatterns": []
}
```

# Actor output Schema

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

One row per URL found in the sitemaps, with lastmod, priority, hreflang and images.

# 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 = {
    "startUrls": [
        {
            "url": "https://crawlee.dev"
        }
    ],
    "maxUrls": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("webprobe-tools/sitemap-url-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 = {
    "startUrls": [{ "url": "https://crawlee.dev" }],
    "maxUrls": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("webprobe-tools/sitemap-url-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 '{
  "startUrls": [
    {
      "url": "https://crawlee.dev"
    }
  ],
  "maxUrls": 100
}' |
apify call webprobe-tools/sitemap-url-extractor --silent --output-dataset

```

## MCP server setup

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