# Sitemap Extractor & Broken Link Checker (`jeanswiegers/sitemap-broken-link-checker`) Actor

Extract every URL from a website's XML sitemaps (robots.txt discovery, sitemap indexes, .gz) with lastmod, check HTTP status codes, and crawl pages to find broken internal and external links with source page and anchor text. Polite: respects robots.txt.

- **URL**: https://apify.com/jeanswiegers/sitemap-broken-link-checker.md
- **Developed by:** [Jean Swiegers](https://apify.com/jeanswiegers) (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

$0.50 / 1,000 url processeds

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 Extractor & Broken Link Checker – All URLs, Status Codes & Dead Links

**Get every URL from a website's sitemap in seconds, then find what's broken.** Give it a homepage or a sitemap URL and it discovers sitemaps automatically (robots.txt, `/sitemap.xml`, `/sitemap_index.xml`), follows **sitemap indexes** and **gzipped sitemaps**, and exports every URL with `lastmod`, `changefreq` and `priority`. Optionally it checks the **HTTP status** of every URL and **crawls your pages to find broken internal and external links**, reporting the page each broken link is on and its anchor text.

### What can I use it for?

- 🔎 **Technical SEO audits** – find 404s, 5xx errors and redirects listed in your sitemap (Google wastes crawl budget on them)
- 🔗 **Broken link checking** – fix dead links before users and search engines hit them, with the exact source page and anchor text
- 🗺️ **Site inventory & content audits** – export all pages with last-modified dates to a spreadsheet
- 🚚 **Website migrations** – collect the full URL list before a redesign and verify redirects afterwards
- 🕵️ **Competitor research** – see how many pages competitors have and what they published recently
- 🤖 **Feed other scrapers / RAG crawlers** – get a clean URL list to process

### Features

- Sitemap discovery via robots.txt plus common locations; XML, **sitemap index**, **.xml.gz** and plain-text sitemaps
- De-duplicated URLs with `lastmod`, `changefreq`, `priority` and the sitemap they came from
- Optional **status check** (HEAD with GET fallback): status code, redirect target, response time
- Optional **broken link crawl** of internal pages: broken links (404/410/5xx/DNS/timeouts) with source page, anchor text and internal/external flag; links blocked by bot protection (401/403/429) are reported separately as `restricted-link` so they don't pollute your broken-link list
- **Polite by design:** respects robots.txt, per-host rate limit, automatic back-off on 429, identifies itself with a clear user agent
- Per-site errors with clear messages; you only pay for URLs actually delivered

### Input example

```json
{
  "startUrls": [{ "url": "https://crawlee.dev" }],
  "maxUrls": 5000,
  "checkStatus": true,
  "crawlForBrokenLinks": true,
  "maxCrawlPages": 200,
  "maxRequestsPerSecond": 4
}
```

### Output example

Sitemap URL row (with `checkStatus`):

```json
{
  "type": "sitemap-url",
  "site": "https://crawlee.dev",
  "url": "https://crawlee.dev/blog",
  "lastmod": null,
  "changefreq": "weekly",
  "priority": 0.5,
  "sitemap": "https://crawlee.dev/sitemap.xml",
  "statusCode": 200,
  "ok": true,
  "redirectedTo": null,
  "responseTimeMs": 75,
  "checkError": null
}
```

Broken link row (with `crawlForBrokenLinks`):

```json
{
  "type": "broken-link",
  "site": "https://crawlee.dev",
  "sourcePage": "https://crawlee.dev/js/api/core/changelog",
  "linkUrl": "https://github.com//github.com/apify/crawlee/blob/f3eb99d9fa9a7aa0ec1dcb9773e666a9ac14fb76/packages/core/src/storages/sitemap_request_list.ts/issues/L446",
  "anchorText": "/github.com/apify/crawlee/blob/f3eb99d9fa9a7aa0ec1dcb9773e666a9ac14fb76/packages/core/src/storages/sitemap_request_list.ts#L446",
  "linkType": "external",
  "statusCode": 404,
  "error": null,
  "redirectedTo": null
}
```

A run summary per site (URLs extracted, pages crawled, broken links, sitemap errors) is saved as `SITE_SUMMARIES` in the key-value store.

### How much does it cost?

Pay per event: **$0.0005 per URL** – each sitemap URL delivered (status check included) and each page crawled for links. That's **$0.50 per 1,000 URLs**. Broken-link rows are included at no extra cost. **No extra platform usage charges.** Set a maximum cost per run and the Actor stops cleanly when it is reached.

### FAQ

**My site has no sitemap.** Turn on `crawlForBrokenLinks` – the crawler discovers pages from links instead.

**Why is a link marked `restricted-link`?** The target answered 401/403/429 – usually a login wall or bot protection (LinkedIn, Stack Overflow…). It probably works in a browser, so we don't call it broken.

**Will this overload my server?** No. The default is 4 requests per second per host, robots.txt is respected and the crawler backs off on 429. Lower `maxRequestsPerSecond` for very small servers.

**Does it render JavaScript?** No – it reads HTML and sitemaps directly, which is fast and cheap. Links injected only by client-side JavaScript are not discovered.

# Changelog

This Actor's version history is a separate document: https://apify.com/jeanswiegers/sitemap-broken-link-checker/changelog.md

# Actor input Schema

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

A homepage (sitemaps are discovered from robots.txt, /sitemap.xml and /sitemap_index.xml) or a direct sitemap URL (.xml, .xml.gz, sitemap index or plain-text sitemap).

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

Stop extracting after this many unique URLs per site.

## `checkStatus` (type: `boolean`):

Request every extracted URL (HEAD, falling back to GET) and add status code, redirect target and response time. Finds 404s and redirects listed in your sitemap.

## `crawlForBrokenLinks` (type: `boolean`):

Crawl the site's internal pages starting from the start URL, check every link and report broken ones with the page they're on and their anchor text.

## `maxCrawlPages` (type: `integer`):

Limit of internal HTML pages crawled for links.

## `checkExternalLinks` (type: `boolean`):

Also check links pointing to other domains.

## `includeOkLinks` (type: `boolean`):

Also output links that work (full link inventory). Off = only broken and restricted links.

## `maxRequestsPerSecond` (type: `integer`):

Rate limit per host. Keep low for small sites. 429 responses trigger automatic back-off.

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

Timeout per request.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://crawlee.dev"
    }
  ],
  "maxUrls": 100,
  "checkStatus": false,
  "crawlForBrokenLinks": false,
  "maxCrawlPages": 100,
  "checkExternalLinks": true,
  "includeOkLinks": false,
  "maxRequestsPerSecond": 4,
  "timeoutSecs": 20
}
```

# Actor output Schema

## `sitemapUrls` (type: `string`):

Every URL from the sitemaps with lastmod, changefreq, priority and optional HTTP status.

## `brokenLinks` (type: `string`):

Broken and restricted links with source page and anchor text (when crawlForBrokenLinks is enabled).

## `siteSummaries` (type: `string`):

Per site: sitemaps found, URLs extracted, pages crawled, broken links, sitemap errors.

# 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"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jeanswiegers/sitemap-broken-link-checker").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" }] }

# Run the Actor and wait for it to finish
run = client.actor("jeanswiegers/sitemap-broken-link-checker").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"
    }
  ]
}' |
apify call jeanswiegers/sitemap-broken-link-checker --silent --output-dataset

```

## MCP server setup

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

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/DNm0OkgOFIEevuL0Q/builds/V48c8EySmi0fffPjd/openapi.json
