findbrokenlinks
Async crawler that finds links on a website whose behavior in a browser would not match user expectations: 404s, network failures, redirects to weird places, "soft 404" pages where a CMS returns 200 but says "not found".
Built around pluggable checks and reporters — adding a new control or
output format means dropping a file with an @register decorator. No core
edits needed.
Features
- Crawl modes:
page(single page),internal(same domain), orinternal+external(recurse internal, validate external) —--mode. - Seven built-in checks — flag HTTP errors, network failures, redirect chains, redirects to the home page, two soft-404 detectors (regex patterns + baseline probing), and an anti-bot block detector so WAF challenges from Cloudflare / DataDome / PerimeterX / Imperva / Akamai / DDoS-Guard and login walls (401) don't masquerade as broken links.
- Polite-but-well-formed HTTP: keeps an honest
User-Agent, but pairs it with standardAcceptandAccept-Languageheaders so WAFs don't treat us as malformed traffic. - Doesn't parse JS as HTML: bodies are only HTML/plaintext; JS, CSS,
JSON aren't read, and HTMLExtractor double-checks
Content-Typebefore invoking bs4 — so JavaScript string literals can't become fake findings. - Nine output formats:
csv,tsv,json,jsonl,html,markdown,junit(XML),sarif,grouped-json. Emit multiple at once with--format a,b,c. grouped-jsonreporter collapses findings byfinal_url— one record per distinct broken target with the source-page list preserved as a count plus a small sample. On a real crawl of a 7800-page site, a single broken footer link generated 7800 findings; grouped-json compresses that to one record (97% reduction in our test case).- Incremental report writing: when a single streamable format is selected
(
csv,tsv,jsonl), each finding is appended to the output as soon as it is discovered — you cantail -fthe report while the crawl runs. - Polite by default: respects
robots.txt, rate-limited (token bucket), bounded concurrency, configurable timeouts and redirect caps. - Bandwidth-efficient: streams responses — binary content (PDFs, archives, images) is never downloaded, only its status code is checked. Text bodies are capped (default 1 MB) so a runaway HTML page can't exhaust memory.
- HTML coverage beyond
<a href>: also checks<img src>,<script src>,<link href>. - Extensible: new check = one file +
@register. Same for report formats. - CI-friendly: exit code
1when a finding reaches--fail-on(defaulterror),3when the crawl itself failed, so CI can tell the two apart; JUnit output slots into CI test reports (GitHub Actions, GitLab, Jenkins). SARIF output is one result per check and broken target; for GitHub Code Scanning it needs--sarif-anchor, see "CI integration" below. - GitHub Action: one step that writes a job summary, annotates the top broken targets and leaves a SARIF report for Code Scanning, see "GitHub Action" below.
Installation
Requires Python 3.11+. From PyPI:
pipx install findbrokenlinks # CLI in its own venv
# or
pip install findbrokenlinks
In GitHub Actions, the action needs no installation step: see GitHub Action.
From a clone, for development:
git clone https://github.com/as-mnt/findbrokenlinks
cd findbrokenlinks
make install # .venv/ with the package in editable mode
# or
make install-dev # + pytest, ruff, mypy, starlette (for integration tests)
In a clone the command is .venv/bin/findbrokenlinks.
Quick start
# Crawl a site, internal pages + validate external links, TSV to stdout
findbrokenlinks https://example.com
# Single page mode, HTML report
findbrokenlinks https://example.com --mode page \
--format html -o report.html
# Streaming JSONL — findings appear in the file as soon as they are discovered
findbrokenlinks https://example.com --format jsonl -o report.jsonl &
tail -f report.jsonl | jq .
# Emit several formats at once
findbrokenlinks https://example.com \
--format csv,json,html,markdown --output-dir reports/
# Run as a Python module
python -m findbrokenlinks https://example.com --mode internal
In a clone, via Makefile shortcuts (override URL=… on the command line):
make run URL=https://example.com
make run-page URL=https://example.com
make run-internal URL=https://example.com
make run-html URL=https://example.com OUT_DIR=reports
make run-jsonl URL=https://example.com OUT_DIR=reports # streaming JSONL
make run-multi URL=https://example.com OUT_DIR=reports
make run-json URL=https://example.com FLAGS=--insecure # forward extra CLI flags
GitHub Action
- uses: as-mnt/findbrokenlinks@v1
with:
url: https://docs.example.org
The step installs findbrokenlinks from the action's own checkout into a
separate virtualenv (the job's Python and PATH are left alone) and crawls the
site. It writes a job summary with the totals and the top broken targets,
::error and ::warning annotations for those targets, and the grouped-json
and sarif reports. It fails when a finding reaches fail-on, with the CLI's
exit codes. It runs on
Linux and macOS runners, not on Windows.
@v1 follows the latest 1.x release. For a fixed version, give a release tag
(@v1.0.0) or its commit SHA.
Inputs
| Input | Default | |
|---|---|---|
url |
required | Start URL, http:// or https://. |
mode |
internal+external |
page, internal or internal+external, as --mode. |
fail-on |
error |
Lowest severity that fails the step: error, warning or never. |
formats |
Extra report formats, comma- or space-separated (csv, html, junit, …). grouped-json and sarif are always written. |
|
args |
Other CLI options, split the way a shell splits words (no variable expansion), e.g. --depth 3 --rate-limit 2. The options the inputs set are refused: --format, --output, --output-dir, --mode, --fail-on, --sarif-anchor. |
|
output-dir |
a new directory | Directory for the reports; {host}, {date}, {time} and {ts} are expanded. By default each run gets a new one, $RUNNER_TEMP/findbrokenlinks/<host> (then <host>-2, …). In a directory given here, the reports an earlier run left there, of any format, and its summary.md are removed first; other files stay. So do not give the repository root (.): its summary.md would be removed too. |
sarif-anchor |
the workflow's file | Repository file, relative to its root, that every SARIF result is attached to (at line 1) for Code Scanning, e.g. mkdocs.yml. By default, the file of the workflow that runs the action. |
python-version |
3.12 |
Python for the action's own virtualenv. |
summary |
true |
Write the job summary. summary.md in report-dir is written either way. |
annotations |
true |
Annotate the top targets. |
max-annotations |
10 |
How many targets to annotate at most. GitHub keeps 10 error and 10 warning annotations per step, so more than 20 changes nothing. |
Outputs
| Output | |
|---|---|
exit-code |
0, 1, 2 or 3, the CLI's exit code. |
errors |
Number of error-level findings (links on pages). Empty when no report was written. |
warnings |
Number of warning-level findings. Empty when no report was written. |
broken-targets |
Number of distinct final URLs with an error. Empty when no report was written. |
report-dir |
Absolute path of the report directory, for actions/upload-artifact. |
sarif-file |
The SARIF report, for github/codeql-action/upload-sarif. Empty when not written. |
summary-file |
summary.md, the job summary as a file (for a pull request comment, say). |
Examples
A published site, every week
name: Links
on:
schedule:
- cron: "0 6 * * 1" # Mondays at 06:00 UTC
workflow_dispatch:
permissions:
contents: read
jobs:
links:
runs-on: ubuntu-latest
steps:
- uses: as-mnt/findbrokenlinks@v1
id: links
with:
url: https://docs.example.org
formats: html
- uses: actions/upload-artifact@v7
if: always() && steps.links.outputs.report-dir != ''
with:
name: link-report
path: ${{ steps.links.outputs.report-dir }}
No checkout: the action does not read the repository. A broken link fails the
run, and GitHub notifies whoever last changed the schedule. The reports, the
HTML one among them, are an artifact of the run. In a public repository GitHub
turns scheduled workflows off after 60 days without activity in it.
A documentation site built in the same job
name: Docs
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- run: pip install mkdocs
- run: mkdocs build
- name: Serve the site
run: |
python -m http.server 8000 --directory site &
curl --silent --retry 10 --retry-connrefused --retry-delay 1 \
--output /dev/null http://localhost:8000/
- uses: as-mnt/findbrokenlinks@v1
with:
url: http://localhost:8000/
mode: internal
The server started in the background keeps running for the steps after it;
curl waits until it answers. mode: internal checks the site's own pages and
links and leaves external ones to the weekly run: a pull request should not fail
because another site is down. It also leaves alone the links to the published
site, such as <link rel="canonical"> with site_url set in mkdocs.yml: a
page new in the pull request is not published yet.
Alerts in Code Scanning
name: Links
on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: as-mnt/findbrokenlinks@v1
id: links
with:
url: https://docs.example.org
fail-on: never
- uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: ${{ steps.links.outputs.sarif-file }}
category: findbrokenlinks/docs.example.org
Each check and broken target is one alert, attached to line 1 of the workflow
file (or of sarif-anchor); the message has the URL and a sample of the pages
that link to it. An alert stays the same alert from run to run and is closed by
the first run that no longer finds it. fail-on: never keeps the run green, the
alerts being the result; the step still fails when the crawl does (exit code 3),
and then the upload is skipped: a partial report would close alerts it did not
get to. category keeps these results apart from other analyses, CodeQL's for
one; give each site its own. Code Scanning is free for public repositories; a
private one needs GitHub Code Security.
CLI reference
findbrokenlinks <URL> [options] URL: http:// or https:// with a host (and a port 1-65535)
Scope:
--mode {page,internal,internal+external} default: internal+external
--depth N default: 0 (unlimited)
--max-pages N default: 10000 (0 = unlimited);
safety cap against unbounded URL spaces
(session IDs, calendars, search facets)
--use-sitemap seed from /sitemap.xml
Network:
--rate-limit RPS default: 5
--concurrency N default: 10
--timeout SECONDS default: 15
--max-redirects N default: 10
--max-body-bytes N default: 1048576 (1 MB) — cap on text bodies;
non-text responses are never downloaded
--user-agent UA default: findbrokenlinks/<version> (+https://github.com/as-mnt/findbrokenlinks)
--ignore-robots
--insecure, -k disable TLS certificate verification (like curl -k).
NOTE: an incomplete chain (server missing its
intermediate CA) is already crawled by default and
reported as a NETWORK_ERROR *warning* — this flag is
for other cert problems (expired, self-signed, wrong
host) and suppresses ssl/ssl_chain findings entirely.
Checks:
--enable-checks code1,code2
--disable-checks code1,code2
--redirect-chain-threshold N default: 3
--patterns PATH user soft-404 patterns YAML (checked at startup)
--no-soft404-probe
--fail-on {error,warning,never}
lowest severity that makes the exit code 1
(default: error); never: exit 0 whatever is found
Output:
--format fmt[,fmt...] csv|tsv|json|jsonl|html|markdown|junit|sarif|grouped-json
(default: tsv); streaming formats: csv, tsv, jsonl
--output PATH, -o PATH default: stdout (single format only). Supports
placeholders {host}, {date}, {time}, {ts}, {format}, {ext}.
--output-dir DIR directory for multi-format output. Defaults to
reports/{host}_{date}_{time}/ when omitted. Files
inside the dir are named {format}.{ext}.
--sarif-anchor PATH sarif: attach every result to line 1 of this file,
relative to the repository root (e.g. mkdocs.yml);
needed for GitHub Code Scanning
Misc:
-v / --verbose
--log-file PATH
Built-in checks
| Code | Severity | Triggers when |
|---|---|---|
HTTP_ERROR |
error | response status ≥ 400 |
NETWORK_ERROR |
error / warning | DNS / TCP / TLS / timeout failure (error). Also warning when a page was crawled over a relaxed TLS chain — i.e. the server omitted its intermediate CA (ssl_chain); the crawl proceeds, the broken chain is flagged so you can ship fullchain.pem. |
REDIRECT_TO_HOME |
warning | redirect terminates at / (common soft-404 pattern) |
REDIRECT_CHAIN |
warning | redirect chain length >= --redirect-chain-threshold |
SOFT_404_PATTERN |
warning | 200 OK but page matches a "not found" regex |
SOFT_404_PROBE |
warning / info | 200 OK but body matches the host's known 404 baseline, or the link redirects where a nonexistent URL does (warning). Info, once per host: the home page itself matches the baseline, so bodies are not compared there. |
ANTIBOT_BLOCKED |
warning | 4xx/5xx response matches a known WAF / anti-bot signature (DataDome, PerimeterX, Cloudflare interstitial, Imperva, Akamai, generic "not a bot" / captcha text). Fires alongside HTTP_ERROR — disable one or the other to suit your triage. |
The probe-based detector requests a random nonexistent URL per host at startup
and remembers the response (status, normalized text, hash). Any 2xx response
whose body matches the baseline is flagged, and so is a link that redirects to
where the nonexistent URL ended up. A link to a home page (/) is not flagged
when it ends up on its own host, or where the home page of the host it ends up
on does: a www. alias, say. Another host's / that lands on a not-found page
is.
The probe also requests the home page (/). If it has the same body as the
nonexistent URL, bodies on that host tell a missing page from a real one in
nothing, so they are not compared: instead of a warning on every page you get
one info finding on the home page that says so. The redirect comparison still
works there.
Single-page apps (SPAs). A client-rendered app (Next.js, React Router, etc.) typically serves the same
index.htmlshell with200 OKfor every path — including the homepage and genuinely nonexistent URLs — and renders the "not found" state in the browser via JavaScript. Since this crawler doesn't execute JS, every page looks identical at the HTTP layer, and broken internal links on such a host can't be detected by HTTP status alone. That is what the oneinfofinding above tells you. Sites likeexample.com, which serve the same page with404for every unknown path, get the same finding.--no-soft404-probeturns the probe off altogether (no requests).
Output
Every reporter produces the same fields per finding:
source_page— page where the link was foundlink_url— the link's target URLfinal_url— where the request actually ended up after redirectsanchor— link text or alt attributetag—a/img/script/link/seedstatus— HTTP status (empty on network error)redirect_chain— list of intermediate URLsissue_codes— which checks firedseverity—error/warning/infodetails— human-readable explanation
HTML and Markdown reports additionally group findings by source page.
junit and sarif leave out info findings. In them every entry asks for a
fix: a failed test, an alert in GitHub Code Scanning. An info finding is a
note about the site, such as "content is not compared on this host"
(SOFT_404_PROBE); the other formats keep it.
Extending: add a new check
No core edits required. Create src/findbrokenlinks/checks/my_check.py:
from findbrokenlinks.checks.base import Check, CheckContext, register
from findbrokenlinks.models import FetchResult, Issue, LinkRef
@register
class SlowResponseCheck(Check):
code = "SLOW_RESPONSE"
severity = "warning"
def evaluate(self, link: LinkRef, fetch: FetchResult, ctx: CheckContext) -> Issue | None:
if fetch.elapsed_ms > 5_000:
return Issue(self.code, self.severity, f"slow: {fetch.elapsed_ms:.0f}ms",
{"ms": fetch.elapsed_ms})
return None
That's it. The package auto-discovers every submodule under checks/ on
import, so dropping the file is enough — no __init__.py edits required.
Your check is now available everywhere, and can be toggled via
--enable-checks SLOW_RESPONSE / --disable-checks SLOW_RESPONSE.
Extending: add a new output format
Same pattern. Create src/findbrokenlinks/reporters/my_reporter.py:
from findbrokenlinks.models import Finding
from findbrokenlinks.reporters.base import Reporter, register
@register
class MyReporter(Reporter):
name = "myfmt"
file_ext = "myx"
def render(self, findings: list[Finding]) -> str:
...
Drop the file under reporters/ — same auto-discovery applies — and you
can now pass --format myfmt.
Extending: custom soft-404 patterns
Built-in patterns live in src/findbrokenlinks/patterns/builtin.yaml. Add your
own without forking — pass --patterns my_patterns.yaml:
- name: my_cms_404
target: title # title | h1 | body | raw
regex: '(?i)not here'
target picks the search surface:
title/h1— text of those elementsbody— full page text after BeautifulSoupget_text()— markup strippedraw— the unaltered HTML body, including tags, attributes, and server signatures that text extraction would erase
User patterns are merged with the built-in set (Composite).
Architecture
seed URL ──► Crawler (asyncio.Queue + N workers)
│
├─► Fetcher ──► httpx.AsyncClient (rate-limited, robots-aware)
├─► HTMLExtractor (bs4 + lxml)
├─► Checks (Strategy + Registry, per-finding evaluation)
└─► Reporter (Strategy + Registry, multiple formats)
Design patterns used:
- Strategy + Registry —
CheckandReporterABCs with@register-driven plug-in collections - Producer–Consumer / Worker Pool —
asyncio.Queue+ N workers - Composite — built-in + user soft-404 patterns merged
- Factory —
get_reporter(name)resolves a format string - Pipeline — Fetcher → Extractor → Checks → Reporter
- Observer —
on_findingcallback drives incremental report writing for streaming formats (csv, tsv, jsonl)
See docs/context.md for the up-to-date design and rationale. docs/plan.md is
the day-0 approved plan, kept as a baseline against which to read the change log.
Development
make install-dev # set up dev environment
make check # ← run before pushing: lint + typecheck + tests
# (mirrors the GitHub Actions pipeline)
make test # run the test suite (~10s)
make test-unit # unit tests only (skip live-server integration)
make test-integration # only the live-server integration test
make lint # ruff
make typecheck # mypy
make package # build sdist + wheel, twine check, smoke-test the
# wheel in a clean venv (mirrors CI job `package`)
make clean # nuke venv, caches, build artifacts, generated reports
Tests run against a local Starlette server with known-broken routes and a
static fixture site (tests/fixtures/site/) — no network access required for CI.
CI integration
Exit codes
| Code | Meaning |
|---|---|
0 |
no finding at or above --fail-on (default error) |
1 |
at least one finding at or above --fail-on |
2 |
bad arguments: unknown option or format, a start URL that is not http(s)://host… or has a bad port, a malformed output path template, a --log-file that cannot be opened, invalid --patterns file, … |
3 |
the crawl failed or is incomplete (a crash, or a URL the crawler could not process); the report, if written, is partial |
3 takes precedence over 1: an incomplete report can't vouch for the site.
--fail-on warning also fails on the warning-level checks: anti-bot blocks,
redirect chains, redirects to the home page, both soft-404 detectors and an
incomplete TLS certificate chain. --fail-on never keeps the job green and
leaves the verdict to the report.
On any CI, the CLI and its exit code are enough. In GitHub Actions, say:
- run: pip install findbrokenlinks
- run: findbrokenlinks https://your-site.example --mode internal+external \
--format junit -o link-check.xml
- uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: link-check.xml
Uploading the SARIF output to GitHub Code Scanning needs --sarif-anchor PATH.
Without it, results are located by page URL, and Code Scanning rejects the whole
upload when an artifactLocation.uri is an http(s):// URL rather than a
repository file (SARIF URI scheme "https" did not match the checkout URI scheme "file"). With it, every result is attached to line 1 of that repository file
(mkdocs.yml, say), and the URLs are in the message. There is one result per
check and broken target, so a dead link in a site-wide footer is one alert, not
one per page. An alert keeps its identity from run to run through a fingerprint
of the check and the target: the message, the anchor file and its first line may
change. The GitHub Action does this by default, see
Alerts in Code Scanning.
Documentation
CHANGELOG.md— what changed, release by releasedocs/task.md— original problem statement and decisionsdocs/plan.md— the implementation plan as approved on day 0 (historical snapshot — seedocs/context.mdfor what actually ships)docs/context.md— implementation snapshot, file layout, how to extend each subsystemdocs/roadmap.md— plan for 1.0.0: PyPI package and GitHub Action
License
MIT — see LICENSE.
Metadata
Release files for findbrokenlinks 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| findbrokenlinks-1.0.0.tar.gz | 111.2 kB | With provenance | Details for findbrokenlinks-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| findbrokenlinks-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for findbrokenlinks-1.0.0-py3-none-any.whl |
Total release size: 183.5 kB
Release files / findbrokenlinks-1.0.0.tar.gz
| Download URL | findbrokenlinks-1.0.0.tar.gz |
|---|---|
| Size | 111.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7cc1e6427ad5d9b045743a44dd755b1108f277f9cba8700b657f9e36e92c2a87
|
|
BLAKE2b-256 checksum How to use checksums |
55c35dc06331a80e249139e105d2e419d65783d945ab9a816147d0c045120fd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / findbrokenlinks-1.0.0-py3-none-any.whl
| Download URL | findbrokenlinks-1.0.0-py3-none-any.whl |
|---|---|
| Size | 72.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
021d0462996fe572eae6663a18ec581ac258dd480b7a030788b0de03814044fe
|
|
BLAKE2b-256 checksum How to use checksums |
8ffd30b6cd8fefdf946fdfb9084e601ed733501b20a74d250bc9325c156c7162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for findbrokenlinks 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for findbrokenlinks-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.