# Sitemap Extractor (`luck777/sitemap-extractor`) Actor

Extracts and parses XML sitemaps from websites. Handles sitemap indexes, image sitemaps, robots.txt discovery, and outputs structured URL data for SEO audits, content inventories, and site migrations.

- **URL**: https://apify.com/luck777/sitemap-extractor.md
- **Developed by:** [Luck Vergouwen](https://apify.com/luck777) (community)
- **Categories:** SEO tools, Developer tools
- **Features:** Limited permissions
- **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 Extractor

Extract every URL from any website's XML sitemaps — including sitemap indexes, image sitemaps, and deeply nested sitemap trees. Built for SEO teams, content auditors, and site migration engineers who need a clean, structured inventory of all indexed pages.

### What it does

For each input URL, the actor:

1. Fetches `robots.txt` and reads all `Sitemap:` directives.
2. Falls back to probing common sitemap paths (`/sitemap.xml`, `/sitemap_index.xml`, `/wp-sitemap.xml`, and others) if `robots.txt` yields nothing.
3. Detects sitemap index files and recursively fetches all child sitemaps.
4. Parses each `<urlset>` sitemap and extracts: `loc`, `lastmod`, `changefreq`, `priority`.
5. Optionally extracts image URLs from image sitemaps (`image:loc`).
6. Outputs one dataset record per domain.

Gzipped sitemaps (`.xml.gz`) are detected and skipped with a note in the `errors` array — they require a decompression library not bundled in this lightweight actor.

### Input

```jsonc
{
  // Required. One or more website or direct sitemap URLs.
  "urls": ["https://example.com", "https://another-site.com/sitemap.xml"],

  // Optional. Extract image URLs from image sitemaps. Default: false.
  "includeImages": false,

  // Optional. Maximum URLs to collect per domain. 0 = unlimited. Default: 50000.
  "maxUrls": 50000
}
```

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `urls` | `string[]` | Yes | — | Root domain URLs or direct sitemap paths |
| `includeImages` | `boolean` | No | `false` | Include `image:loc` entries in output |
| `maxUrls` | `integer` | No | `50000` | Per-domain URL cap (0 = unlimited) |

You can pass either a root domain (`https://example.com`) or a direct sitemap URL (`https://example.com/sitemap.xml`). The actor handles both.

### Output

One dataset record per input domain:

```jsonc
{
  "domain": "example.com",
  "inputUrl": "https://example.com",
  "sitemapUrls": [
    "https://example.com/sitemap_index.xml",
    "https://example.com/sitemap-posts.xml",
    "https://example.com/sitemap-pages.xml"
  ],
  "totalUrls": 1842,
  "urls": [
    {
      "loc": "https://example.com/blog/post-1",
      "lastmod": "2024-11-01",
      "changefreq": "weekly",
      "priority": "0.8",
      "images": ["https://example.com/img/hero.jpg"]  // only if includeImages: true
    }
    // ... more entries
  ],
  "errors": [],
  "scannedAt": "2024-11-18T12:34:56.789Z"
}
```

| Field | Type | Description |
|-------|------|-------------|
| `domain` | `string` | Hostname extracted from the input URL |
| `inputUrl` | `string` | Original URL as provided in input |
| `sitemapUrls` | `string[]` | All sitemap files fetched (root + child sitemaps) |
| `totalUrls` | `integer` | Count of URL entries in the `urls` array |
| `urls` | `object[]` | Extracted URL entries (see below) |
| `errors` | `string[]` | Non-fatal errors encountered during extraction |
| `scannedAt` | `string` | ISO 8601 timestamp when extraction ran |

#### URL entry fields

| Field | Type | Description |
|-------|------|-------------|
| `loc` | `string` | The page URL (always present) |
| `lastmod` | `string\|null` | Last modified date as declared in the sitemap |
| `changefreq` | `string\|null` | Change frequency hint (`daily`, `weekly`, etc.) |
| `priority` | `string\|null` | Priority score between `0.0` and `1.0` |
| `images` | `string[]\|undefined` | Image URLs (only present when `includeImages: true`) |

### Common use cases

#### SEO audit

Run against your domain to get a full picture of what Google is being told to crawl. Cross-reference with your analytics to find pages that are sitemapped but receive no traffic, or pages that rank but are missing from the sitemap.

#### Content inventory

Export the dataset to CSV (via the Apify console) and sort by `lastmod` to find stale content. Filter by URL patterns to categorise content types (blog posts vs. product pages vs. landing pages).

#### Site migration

Run the actor before and after a migration. Compare the two URL lists to verify that all URLs have been properly redirected and that no pages were accidentally dropped from the new sitemap.

#### Competitor research

Input a competitor's domain to get a rough inventory of their content structure and publishing cadence (via `lastmod` and `changefreq` values).

### Limitations

- **Gzipped sitemaps** (`.xml.gz`) are detected and skipped. A note is added to the `errors` array for each skipped sitemap.
- **Non-standard XML** that is heavily malformed may not parse correctly. Standard WordPress, Yoast, Rank Math, and Google-generated sitemaps are fully supported.
- **JavaScript-rendered sitemaps** are not supported — the actor fetches raw HTTP responses only.
- **Password-protected or IP-restricted sitemaps** will return a non-200 status and be reported in `errors`.

### Pricing

This actor uses per-event charging. You are charged **$0.01 per domain** processed, regardless of how many sitemaps or URLs are extracted. There is no charge for failed domains where no sitemaps could be found.

### Technical details

- Runtime: Node.js 22 on `apify/actor-node:22` (lightweight, no browser)
- XML parsing: regex-based (no external parser dependency)
- Dependencies: `apify` SDK only
- Memory: 128 MB minimum, 256 MB recommended for large sites (100k+ URLs)
- Timeout: 30 seconds per HTTP request; actors run with Apify's default run timeout

# Actor input Schema

## `urls` (type: `array`):

List of website URLs (or direct sitemap URLs) to extract sitemaps from. You can pass root domains (e.g. https://example.com) or direct sitemap paths (e.g. https://example.com/sitemap.xml). One result object is produced per domain.

## `includeImages` (type: `boolean`):

When enabled, image URLs embedded in image sitemaps (image:loc tags) are extracted and added to each URL entry under the 'images' key.

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

Maximum number of URL entries to collect per domain. Processing stops once this limit is reached. Use 0 for no limit.

## Actor input object example

```json
{
  "urls": [
    "https://example.com"
  ],
  "includeImages": false,
  "maxUrls": 50000
}
```

# Actor output Schema

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

All URLs extracted from XML sitemaps with lastmod, changefreq, and priority.

# 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 = {
    "urls": [
        "https://example.com"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("luck777/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 = { "urls": ["https://example.com"] }

# Run the Actor and wait for it to finish
run = client.actor("luck777/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 '{
  "urls": [
    "https://example.com"
  ]
}' |
apify call luck777/sitemap-extractor --silent --output-dataset

```

## MCP server setup

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