# Sitemap Generator – Crawl a Website & Create sitemap.xml (`gazidev/sitemap-generator`) Actor

XML sitemap generator: crawls your website (robots.txt respected) and writes a ready-to-upload sitemap.xml with lastmod dates, hreflang alternates and optional image entries. Skips noindex, non-canonical, redirected and broken pages. Splits at 50,000 URLs. $0.50 per 1,000 pages.

- **URL**: https://apify.com/gazidev/sitemap-generator.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 92.3% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 page crawleds

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 Generator – Crawl a Website & Create sitemap.xml

**Sitemap Generator** crawls your website the way a search engine does and writes a ready-to-upload **XML sitemap** (`sitemap.xml`). Only pages that search engines should index are listed: `noindex` pages, non-canonical duplicates, redirects, broken pages and URLs blocked by robots.txt are left out automatically. Each URL gets a `<lastmod>` date when the site provides a real one, `hreflang` alternates for multilingual sites, and optional image entries.

- Enter your home page, press **Start**, then download `sitemap.xml` from the run's **Output** tab.
- Large sites are split automatically at **50,000 URLs** per file, with a `sitemap_index.xml`.
- A table explains every URL: in the sitemap or not, and why.
- **$0.50 per 1,000 pages** crawled. No subscription, no monthly fee.

### What it does

1. Reads your `robots.txt` (disallowed URLs are never fetched, `Crawl-delay` is honored).
2. Crawls your site breadth-first, so the most important pages come first, staying on your host (`www` and non-`www` count as one site).
3. For each page it checks the HTTP status, the `robots` meta tag, the `X-Robots-Tag` header, `rel="canonical"` (HTML tag or `Link` header), `hreflang` alternates, images and modification dates.
4. Writes `sitemap.xml` (sitemaps.org protocol 0.9, valid XML, URLs percent-encoded and XML-escaped) to the run's key-value store, and lists every crawled URL in the dataset.

#### Which pages go into the sitemap

| Page | In the sitemap? |
|---|---|
| HTML page, HTTP 200, indexable, canonical points to itself (or no canonical) | ✅ yes |
| `noindex` in robots meta tag or X-Robots-Tag header | ❌ `noindex` (can be turned on with *Keep noindex pages*) |
| `rel="canonical"` points to another URL | ❌ `nonCanonical` (the canonical URL is crawled instead) |
| Redirect (301, 302, 307, 308) | ❌ `redirect` (the target page is added if it is on your site) |
| 4xx / 5xx, timeouts, DNS errors | ❌ `httpError` / `fetchError` |
| PDFs, images, other non-HTML files | ❌ not crawled |
| Disallowed by robots.txt | ❌ never fetched |
| URLs with `?query` parameters | ❌ skipped by default (turn off *Skip URLs with ?query parameters* if your pages need them) |

#### Where `<lastmod>` comes from

1. JSON-LD `dateModified` in the page (WordPress/Yoast, Shopify, most CMSs), or the `article:modified_time` / `og:updated_time` meta tag.
2. Otherwise the `Last-Modified` HTTP header (static sites, GitHub Pages, S3, Netlify).
3. Otherwise no `<lastmod>`. Dynamic pages often send "now" as `Last-Modified`; such headers are ignored, because Google stops trusting `lastmod` values that are always new. Every dataset row shows `lastmodSource`.

### Use cases

- Create a sitemap for a site whose CMS has none (custom sites, static HTML, old PHP sites, single-page builders).
- Rebuild a stale or broken sitemap and submit it in Google Search Console and Bing Webmaster Tools.
- Compare what is really crawlable with the sitemap you have (the dataset shows every excluded URL and the reason).
- Generate a sitemap for a multilingual site, including `hreflang` alternates.
- Run it on a schedule and download the newest `sitemap.xml` through the API.

### Input example

```json
{
  "startUrl": "https://www.example.com",
  "maxPages": 2000,
  "addLastmod": true,
  "addHreflang": true,
  "addImages": false,
  "excludeGlobs": [{ "glob": "https://www.example.com/cart/**" }]
}
```

Set **Max pages to crawl** a bit above the number of pages on your site (default 100). The run stops at that limit and still writes a valid sitemap with what it found.

### Output

**Key-value store** (Output tab):

- `sitemap.xml`: the sitemap, ready to upload to your web root.
- More than 50,000 URLs (or ~45 MB): `sitemap-1.xml`, `sitemap-2.xml`, … plus `sitemap_index.xml` pointing to them. Set *Where you will upload the sitemap* if the files will not live at your site root.
- `OUTPUT`: download links for every file, the line to add to robots.txt (`Sitemap: https://www.example.com/sitemap.xml`), and counts of included and excluded URLs by reason.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://www.example.com/</loc>
    <lastmod>2026-10-02T08:15:00+00:00</lastmod>
    <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/de/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/"/>
  </url>
</urlset>
```

**Dataset**: one row per fetched URL:

```json
{
  "url": "https://crawler-test.com/canonical_tags/canonical_tag",
  "inSitemap": false,
  "excludedReason": "nonCanonical",
  "status": 200,
  "lastmod": null,
  "lastmodSource": null,
  "canonical": "https://crawler-test.com/",
  "noindex": false,
  "hreflang": [],
  "title": "Canonical Tag",
  "redirectedTo": null,
  "depth": 1,
  "foundOn": "https://crawler-test.com/"
}
```

### Pricing

Pay per event: **$0.0005 per page crawled** ($0.50 per 1,000 pages) plus a tiny Actor start fee ($0.00005).

- A page is charged when its HTML was downloaded and analysed, **including pages that are then left out** of the sitemap as `noindex` or non-canonical. The crawler has to download them to find that out, and to find the links on them.
- Free: redirects, 4xx/5xx errors, timeouts, non-HTML files, and URLs blocked by robots.txt or your exclude globs (those are never fetched).
- Set a **maximum cost per run** in the run options: the crawl stops at that amount and still writes a valid sitemap of the pages found so far (`stoppedAtMaxCharge: true` in OUTPUT).

| Site size | Cost |
|---|---|
| 100 pages | $0.05 |
| 1,000 pages | $0.50 |
| 10,000 pages | $5.00 |

Compared with other sitemap tools in Apify Store (November 2026): one sitemap *generator* charges $0.099 per page; the popular "sitemap" Actors are *extractors* that read an existing sitemap rather than create one.

### FAQ

**How do I use the sitemap?** Download `sitemap.xml`, upload it to your web root (`https://www.example.com/sitemap.xml`), add the `Sitemap:` line from OUTPUT to your robots.txt and submit the URL in Google Search Console.

**Does it render JavaScript?** No. It reads the HTML the server sends, like most crawlers. Links that only appear after JavaScript runs (some single-page apps) are not discovered. Server-rendered sites, WordPress, Shopify, Wix, Squarespace and static sites work.

**Why is my sitemap smaller than my site?** Check the dataset: every excluded URL has an `excludedReason`, and OUTPUT counts URLs that were never fetched (`maxPages`, `maxDepth`, `robotsTxtDisallowed`, `hasQueryString`, `excludeGlobs`). Pages that are not linked from anywhere (orphan pages) cannot be found by crawling.

**Does it add `<priority>` and `<changefreq>`?** No `<priority>`. `<changefreq>` is optional (one value for all URLs). Google ignores both.

**Can it crawl sites behind a login or bot protection?** No. It sends honest requests with the User-Agent `gazidev-sitemap-generator/0.1`, does not bypass bot protection and does not log in. Sites that block it give HTTP 403 rows.

**Is robots.txt respected?** Yes, by default: disallowed URLs are not fetched and not listed, `Crawl-delay` (up to 10 s) is honored, and meta `nofollow` pages are not followed. Turn this off only for a website you own.

**Image sitemaps?** Turn on *Add image entries* to add `<image:image>` entries for every `<img>` on each page (up to 1,000 per page).

### Use with AI agents / Apify MCP

The Actor works as a tool in the [Apify MCP server](https://mcp.apify.com) (Claude, Cursor, ChatGPT and other MCP clients). Example prompt: *"Generate a sitemap for https://www.example.com with up to 500 pages and give me the download link."* The agent calls `gazidev/sitemap-generator` with `{"startUrl": "...", "maxPages": 500}` and reads `sitemapUrl` from the `OUTPUT` record. Through the API, call the run-sync endpoint and fetch `/key-value-stores/{storeId}/records/sitemap.xml`.

### Limits

- One website per run (the start URL's host; `www` and non-`www` are treated as the same site).
- Up to 100,000 pages per run. No JavaScript rendering.
- Pages are fetched with plain HTTP from Apify's datacenter IPs; sites that block datacenter traffic return 403 and are left out.
- Duplicate URLs without a canonical tag (e.g. `/` and `/index.html`) are both listed: add canonical tags to your pages or use exclude globs.

# Actor input Schema

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

Home page of the website to put in the sitemap, e.g. `https://www.example.com`. The crawler stays on this host (www and non-www count as the same site). `https://` is added if missing. Empty input runs a small demo on crawler-test.com.

## `maxPages` (type: `integer`):

Maximum number of URLs fetched (breadth-first, so the most important pages come first). Set it a bit above the number of pages on your site. Only HTML pages that were downloaded are charged.

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

How many clicks away from the start page the crawler goes. `0` = only the start page.

## `addLastmod` (type: `boolean`):

Adds `<lastmod>` from the page's JSON-LD `dateModified` or `article:modified_time` meta tag, otherwise from the `Last-Modified` HTTP header. A header that is just the current time (dynamic pages) is ignored, so no fake dates are written.

## `addHreflang` (type: `boolean`):

Copies each page's `<link rel="alternate" hreflang="…">` tags into the sitemap as `<xhtml:link>` entries (multilingual sites). Pages without hreflang tags are unaffected.

## `addImages` (type: `boolean`):

Adds `<image:image>` entries (Google image sitemap extension) for every `<img>` on the page, up to 1,000 per page.

## `changefreq` (type: `string`):

Optional `<changefreq>` value for every URL. Google ignores it; leave empty unless another tool needs it.

## `includeNoindexPages` (type: `boolean`):

Off (recommended): pages with `noindex` in a robots meta tag or X-Robots-Tag header are left out.

## `includeNonCanonicalPages` (type: `boolean`):

Off (recommended): pages whose `rel=canonical` points to another URL are left out (the canonical URL is crawled instead).

## `sitemapBaseUrl` (type: `string`):

Only used when the site has more than 50,000 URLs: the `sitemap_index.xml` points to `<this URL>/sitemap-1.xml`, `/sitemap-2.xml`, … Default: the site root, e.g. `https://www.example.com`.

## `includeGlobs` (type: `array`):

Optional. Only URLs matching one of these globs go into the sitemap, e.g. `https://www.example.com/blog/**`. Other pages are still crawled (and charged) to discover links. `*` matches within one path segment, `**` matches anything.

## `excludeGlobs` (type: `array`):

Optional. URLs matching these globs are never fetched, e.g. `https://www.example.com/cart/**` or `**/tag/**`.

## `skipUrlsWithQueryString` (type: `boolean`):

On (recommended): links with `?…` (filters, sorting, tracking, pagination parameters) are not crawled. Turn off if your real pages use query strings, e.g. `/page.php?id=5`.

## `respectRobotsTxt` (type: `boolean`):

Do not fetch URLs disallowed by robots.txt (they are also kept out of the sitemap), honor Crawl-delay (up to 10 s) and meta `nofollow`. Turn off only for a website you own.

## `concurrency` (type: `integer`):

How many requests are sent to the website at the same time. Keep it low to stay polite. Forced to 1 when robots.txt sets a Crawl-delay.

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

A page that does not answer within this time is left out with error `TIMEOUT`.

## Actor input object example

```json
{
  "startUrl": "https://crawler-test.com/",
  "maxPages": 8,
  "maxDepth": 20,
  "addLastmod": true,
  "addHreflang": true,
  "addImages": false,
  "changefreq": "",
  "includeNoindexPages": false,
  "includeNonCanonicalPages": false,
  "skipUrlsWithQueryString": true,
  "respectRobotsTxt": true,
  "concurrency": 5,
  "timeoutSecs": 15
}
```

# Actor output Schema

## `sitemap` (type: `string`):

No description

## `sitemapIndex` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `pages` (type: `string`):

No description

# 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://crawler-test.com/",
    "maxPages": 8
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/sitemap-generator").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://crawler-test.com/",
    "maxPages": 8,
}

# Run the Actor and wait for it to finish
run = client.actor("gazidev/sitemap-generator").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://crawler-test.com/",
  "maxPages": 8
}' |
apify call gazidev/sitemap-generator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gazidev/sitemap-generator"
        }
    }
}
```

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/yPgGS4IyXnlNJR2EJ/builds/TfFMEdTor9dMkBLdY/openapi.json
