# Broken Link Checker – 404s with Source Pages & Anchor Text (`adamplaenitz/broken-link-checker`) Actor

Crawl a website and check every internal and external link (optionally images, scripts, CSS): status code, error type (DNS, timeout, SSL, 4xx, 5xx), redirect target and all source pages with anchor text. One row per broken link, priced per crawled page.

- **URL**: https://apify.com/adamplaenitz/broken-link-checker.md
- **Developed by:** [Adam Plänitz](https://apify.com/adamplaenitz) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 crawled pages

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

## Broken Link Checker – 404s with Source Pages & Anchor Text

**Crawl your website and check every internal and external link – and optionally images, scripts and stylesheets. You get one row per broken link with the status code, the error type (DNS, timeout, SSL, 4xx, 5xx …), the redirect target and *every page that contains the link, with its anchor text* – so you know exactly where to fix it.** Export as CSV/Excel/JSON or send the results to Google Sheets, Slack, Make, Zapier, n8n or a webhook.

### What does it do?

- **Crawls your site** from one or more start URLs: internal pages only (same domain incl. subdomains, or same hostname), with maximum pages, maximum depth, include / exclude patterns and an option to respect robots.txt.
- **Checks every link it finds** – internal and external, plus images, scripts, stylesheets and icons if you want. Internal pages that were crawled anyway are not requested twice.
- **Polite and robust link checks:** HEAD request first, GET as fallback for servers that refuse HEAD, redirects followed one by one (up to 10), one retry for timeouts, connection errors, 5xx and 429 (honouring `Retry-After`), and a limit of parallel requests per external host.
- **Clear results:** one row per unique broken link with `statusCode`, `errorType`, `redirectTarget`, `finalStatusCode`, `sourceCount` and a `sources` list (page URL, anchor text, tag, nofollow). Links that bot protection refuses (401, 403, 429, LinkedIn's 999) are labelled `blocked` instead of `broken`, so you can check them manually rather than chase false alarms.
- **Output modes:** broken links only (default), broken links plus redirects (great for cleaning up internal redirects after a migration), or every link with its status (full link inventory).
- **Run summary** in `RUN-SUMMARY`: pages crawled, unique links, internal/external counts, counts per status and error type.

### Who is it for?

- **Website owners and SEO agencies** running regular site audits.
- **Developers and content teams** checking a site before and after a relaunch or migration.
- **Agencies** reporting broken links to clients – the source page and anchor text make every finding actionable.

### Input

| Field | Example |
|---|---|
| Start URLs | `https://example.com` |
| Maximum pages to crawl | `500` |
| Maximum link depth | `20` (0 = start URLs only) |
| Which pages count as internal | Same domain incl. subdomains / Same hostname |
| Check external links | on |
| Check images, scripts and stylesheets | off |
| Output | Broken links only / Broken links and redirects / All links |
| Report links blocked for bots | on |
| Respect robots.txt | on |
| Crawl only pages matching | `/blog/*` |
| Do not crawl pages matching | `*?replytocom=*`, `/tag/*` |
| Ignore links matching | `https://www.linkedin.com/*` |
| Parallel requests / per external host | `10` / `3` |
| Request timeout (seconds) | `15` |

**Pattern syntax:** `*` matches any characters. Patterns starting with `/` are matched against the path, other patterns against the full URL; regular expressions go between slashes, e.g. `/(tag|author)/`.

### Output example (shortened)

```json
{
  "url": "https://example.com/old-pricing",
  "linkStatus": "broken",
  "statusCode": 301,
  "errorType": "4xx",
  "redirectTarget": "https://example.com/pricing-2024",
  "finalStatusCode": 404,
  "redirectCount": 1,
  "isInternal": true,
  "resourceType": "link",
  "sourceCount": 2,
  "firstSourcePage": "https://example.com/",
  "firstAnchorText": "Pricing",
  "sources": [
    { "pageUrl": "https://example.com/", "anchorText": "Pricing", "tag": "a", "nofollow": false },
    { "pageUrl": "https://example.com/blog/launch", "anchorText": "see our prices", "tag": "a", "nofollow": false }
  ],
  "checkedWith": "HEAD",
  "responseTimeMs": 412
}
```

- `linkStatus`: `broken`, `blocked`, `redirect`, `ok` or `not-checked` (e.g. disallowed by robots.txt; only in the "all links" mode).
- `errorType`: `4xx`, `5xx`, `dns`, `timeout`, `ssl`, `connection`, `redirect-loop`, `too-many-redirects`, `invalid-url` (malformed href) or `blocked`.
- `statusCode` is the first response, `finalStatusCode` the response at the end of the redirect chain.
- Up to 100 source pages are listed per link; `sourceCount` is the full number.
- If no broken link is found, the dataset contains a single row with `linkStatus: "no-broken-links-found"` and a short message, so scheduled runs and integrations always get a result.

### Pricing and speed

See the **Pricing** tab. You pay **per crawled page** – all links on that page (internal, external and resources) are checked at no extra cost, and the result rows are free. `Maximum pages to crawl` therefore also caps your cost; when your maximum cost per run is reached, the crawl stops and the links found so far are still checked and reported.

Speed in our tests: the prefilled example (3 pages, 421 unique links) takes about 35 seconds; 30 pages of a small shop demo site with 453 unique links take about 10 seconds. Run time depends mostly on the number of unique **external** links per host, because each external host gets at most 3 parallel requests by default: 100 pages of a documentation site with 3,355 unique links (2,139 external, mostly GitHub source links) took about 14 minutes. Raise "Parallel requests per external host" or exclude such links with "Ignore links matching" if you want it faster.

### Robots.txt, permissions and privacy

- **Only check websites you own or are allowed to crawl.** The crawler identifies itself with the User-Agent `broken-link-checker/0.1 (Apify Actor)` and respects robots.txt by default (pages disallowed for it are not crawled). External links are checked with a single request each, like a visitor clicking the link; robots.txt of external sites is not consulted for these single checks.
- Keep the number of parallel requests low for small servers.
- **No personal data is extracted**: the output contains URLs, status codes and the anchor texts of links on the crawled pages.

### Limits

- Pages are fetched without a browser: links that only appear after JavaScript runs (single-page apps) are not found. Links in PDFs or other documents are not followed.
- Some sites answer automated requests with 403/429/999 or block cloud IP addresses – such links are reported as `blocked`. You can use a proxy in the input for your own site.
- Only internal HTML pages are crawled; files (PDF, images, ZIP …) are status-checked but not parsed.
- At most 100 source pages are listed per link (the count is complete).

Questions or feature requests? Please open an issue in the **Issues** tab.

# Actor input Schema

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

Pages where the crawl starts, usually your homepage (e.g. https://example.com). Only check websites you own or are allowed to crawl.

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

Stop crawling after this many pages. Every link found on the crawled pages is still checked. You pay per crawled page, so this also caps the cost.

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

How many clicks away from a start URL the crawler follows internal links. 0 = only the start URLs.

## `crawlScope` (type: `string`):

Same domain: the start host and its subdomains (blog.example.com). Same hostname: only the start host. "www." is ignored in both cases. Only internal pages are crawled; external links are checked but not crawled.

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

Also check links to other websites (one polite HEAD/GET request each, limited parallel requests per external host).

## `checkResources` (type: `boolean`):

Also check the src/href of img, script, stylesheet and icon tags (finds missing images and broken CSS/JS files).

## `outputMode` (type: `string`):

Broken links only (default), broken links plus redirecting links, or every link with its status (full link inventory).

## `includeBlocked` (type: `boolean`):

Many sites (e.g. LinkedIn, some shops) refuse automated requests. These links are reported with status "blocked" so you can check them manually. Switch off to hide them.

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

Do not crawl pages that robots.txt disallows (they are listed as "not-checked" in the full output). Single external link checks do not consult robots.txt, just like a visitor clicking the link.

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

Optional. Glob patterns (`*` = any characters) for internal pages to crawl, matched against the full URL or – if they start with `/` – against the path, e.g. `/blog/*`. Regular expressions go between slashes, e.g. `/(en|de)/`. Start URLs are always crawled.

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

Optional. Same syntax, e.g. `*?replytocom=*` or `/tag/*`. Links to these pages are still checked, but the pages are not crawled.

## `ignoreLinkPatterns` (type: `array`):

Optional. Links matching these patterns are neither checked nor reported, e.g. `https://www.linkedin.com/*` or `*/cdn-cgi/*`.

## `maxConcurrency` (type: `integer`):

Maximum parallel requests overall (1–50). Your own website gets up to this many; external hosts are limited separately (see below).

## `maxRequestsPerExternalHost` (type: `integer`):

Politeness limit for other websites (1–10). Pages with hundreds of links to one host (e.g. "Edit on GitHub" links) are checked faster with a higher value – or skip them with "Ignore links matching".

## `requestTimeoutSecs` (type: `integer`):

A link that does not answer within this time counts as a timeout (after one retry).

## `proxyConfiguration` (type: `object`):

Optional. Only needed if your website blocks requests from cloud servers.

## Actor input object example

```json
{
  "startUrls": [
    "https://crawler-test.com/links/broken_links_internal",
    "https://crawler-test.com/links/broken_links_external"
  ],
  "maxPages": 20,
  "maxDepth": 1,
  "crawlScope": "same-domain",
  "checkExternalLinks": true,
  "checkResources": false,
  "outputMode": "broken",
  "includeBlocked": true,
  "respectRobotsTxt": true,
  "maxConcurrency": 10,
  "maxRequestsPerExternalHost": 3,
  "requestTimeoutSecs": 15,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

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

One item per broken (or, depending on the output mode, redirecting / any) link, with all source pages and anchor texts.

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

Pages crawled, unique links, counts per link status and error type.

# 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": [
        "https://crawler-test.com/links/broken_links_internal",
        "https://crawler-test.com/links/broken_links_external"
    ],
    "maxPages": 20,
    "maxDepth": 1
};

// Run the Actor and wait for it to finish
const run = await client.actor("adamplaenitz/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": [
        "https://crawler-test.com/links/broken_links_internal",
        "https://crawler-test.com/links/broken_links_external",
    ],
    "maxPages": 20,
    "maxDepth": 1,
}

# Run the Actor and wait for it to finish
run = client.actor("adamplaenitz/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": [
    "https://crawler-test.com/links/broken_links_internal",
    "https://crawler-test.com/links/broken_links_external"
  ],
  "maxPages": 20,
  "maxDepth": 1
}' |
apify call adamplaenitz/broken-link-checker --silent --output-dataset

```

## MCP server setup

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