# Sitemap URL Extractor: Sitemap.xml to URL List (`firebrick_zamia/sitemap-url-extractor`) Actor

Extract all URLs from a website's sitemap: finds sitemaps via robots.txt and /sitemap.xml, follows sitemap indexes and .gz files, returns url, lastmod, changefreq and priority. Filter by regex or lastmod date. Respects robots.txt. No browser, no AI.

- **URL**: https://apify.com/firebrick_zamia/sitemap-url-extractor.md
- **Developed by:** [Aadam Ahmed](https://apify.com/firebrick_zamia) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 84.6% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.05 / 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.

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

## Sitemap URL Extractor: Sitemap.xml to URL List

**Get every URL a website lists in its sitemaps. Give it domains or sitemap URLs; it finds sitemaps through robots.txt and /sitemap.xml, follows sitemap indexes and gzip files, and returns url, lastmod, changefreq and priority per row, with regex and date filters. No browser, no AI, no key.**

### What you get

One row per URL: `{url, lastmod, changefreq, priority, sitemap}`. `sitemap` is the sitemap file the URL came from. Fields the sitemap does not provide are null; `priority` is a number.

### Use cases

- Build a crawl list for a site audit, SEO review or content inventory.
- Feed a list of URLs into a scraper or into the Website Change Monitor.
- Find recently updated pages with the `lastmod` filter.
- Compare a competitor's sitemap over time (schedule a run and diff the datasets).
- Give an AI agent a clean list of a site's pages (callable through Apify's MCP server, https://mcp.apify.com).

### How it works

- **Domain input** (`example.com`): reads `https://example.com/robots.txt`, collects its `Sitemap:` lines and also tries `/sitemap.xml` if that is not already listed.
- **Sitemap URL input** (path ends in `.xml` or `.xml.gz`, or contains "sitemap"): read directly.
- **Sitemap indexes** are followed (up to 5 levels deep); each sitemap file is read once. **Gzip** files are decompressed when the data is gzip (up to 100 MB uncompressed).
- **Filters**: `includePatterns` (a URL must match at least one), `excludePatterns` (a URL must match none), `lastmodSince` (YYYY-MM-DD) and `maxUrls`. Duplicate URLs are returned once.
- **Polite by design**: `robots.txt` is checked for every sitemap request (a disallowed sitemap is skipped with a warning; if `robots.txt` cannot be fetched because of a server error or timeout, that site is not fetched), sequential requests at most 1 per second per host, an identifying User-Agent, a timeout and redirects followed with the same checks. No proxies or workarounds.

### Input

| Field | Meaning |
|---|---|
| `domains` | Domains or sitemap URLs, one per line (required, up to 50) |
| `includePatterns` | Regex list; keep URLs matching at least one |
| `excludePatterns` | Regex list; drop URLs matching any |
| `lastmodSince` | Keep URLs modified on or after this day; URLs without a readable `lastmod` are dropped |
| `maxUrls` | Stop after this many matching URLs (default 1,000) |
| `maxSitemaps` | Cap on sitemap files fetched (default 200) |
| `timeoutSecs` | Per-request timeout (default 30 s) |

### Example

Input (bundled `test-input.json`): `example.com`. The record below uses **illustrative values only**; our tests use synthetic sitemap files, including a sitemap index and a gzip file.

```json
{ "url": "https://example.com/blog/hello", "lastmod": "2026-10-01", "changefreq": "weekly", "priority": 0.8, "sitemap": "https://example.com/sitemap-posts.xml" }
```

### Limitations (read before relying on it)

- **Only what the site publishes.** A sitemap is the site owner's own list; it can be incomplete, stale or absent. A site with no reachable sitemap returns nothing (the run fails with the reasons if every sitemap failed).
- **Discovery is limited to `robots.txt` and `/sitemap.xml`.** Other locations (for example `/sitemap_index.xml`) are found only if `robots.txt` lists them or you pass them as a sitemap URL.
- **Image, video and news extensions are not extracted**; only the page `<loc>` and the standard fields. Plain-text sitemaps and RSS/Atom feeds are not supported.
- **`lastmod`, `changefreq` and `priority` are returned as published** and are often missing or unreliable. `lastmodSince` drops entries with no readable date.
- **Regex filters** are JavaScript regular expressions, searched anywhere in the URL; patterns are limited to 200 characters, and very complex patterns on very large sitemaps can be slow.
- Respects `robots.txt`; it does not bypass blocks, logins or CAPTCHAs, and a 403 or 429 is reported as a warning for that file. Check the site's terms before reusing its URL list.
- Large sites take time: files are fetched one at a time, at least one second apart per host.

### Pricing (pay per result)

Pay-per-event with Apify's built-in dataset-item event: each URL row pushed is one result. Use `maxUrls` and the filters to control cost. The live price is set in Apify Console and shown on the Store page.

### FAQ

**Do I need an API key?** No.

**Can I pass several domains?** Yes, up to 50 per run; each is discovered separately.

**Why are some sitemaps skipped?** The warnings in the run log say why: disallowed by robots.txt, HTTP error, not valid sitemap XML or limits reached.

**Does it crawl the pages?** No. It only reads sitemap files, never the pages themselves.

# Actor input Schema

## `domains` (type: `array`):

One per line. A domain (example.com) is searched for sitemaps in its robots.txt and at /sitemap.xml. A URL whose path ends in .xml or .xml.gz, or contains 'sitemap', is read directly as a sitemap.

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

Keep only URLs matching at least one of these regular expressions, for example /blog/ or .pdf$. Empty keeps all. Matching is a search anywhere in the URL.

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

Drop URLs matching any of these regular expressions, for example /tag/ or ?replytocom. Applied after the include patterns.

## `lastmodSince` (type: `string`):

Keep only URLs whose lastmod is on or after this day, YYYY-MM-DD. URLs with no readable lastmod are dropped when this is set.

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

Stop after this many matching URLs (1 to 1,000,000). Each URL is one billed result.

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

Safety cap on the number of sitemap files fetched across all domains, including index files (1 to 5000). Files are fetched one at a time, at most 1 request per second per host.

## `timeoutSecs` (type: `integer`):

Give up on a single request after this many seconds. A failed sitemap is logged as a warning and skipped.

## Actor input object example

```json
{
  "domains": [
    "www.gov.uk"
  ],
  "maxUrls": 100,
  "maxSitemaps": 3,
  "timeoutSecs": 30
}
```

# Actor output Schema

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

All result 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 = {
    "domains": [
        "www.gov.uk"
    ],
    "maxUrls": 100,
    "maxSitemaps": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("firebrick_zamia/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 = {
    "domains": ["www.gov.uk"],
    "maxUrls": 100,
    "maxSitemaps": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("firebrick_zamia/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 '{
  "domains": [
    "www.gov.uk"
  ],
  "maxUrls": 100,
  "maxSitemaps": 3
}' |
apify call firebrick_zamia/sitemap-url-extractor --silent --output-dataset

```

## MCP server setup

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