# Seo Broken Internal Links (`eichan/seo-broken-internal-links`) Actor

- **URL**: https://apify.com/eichan/seo-broken-internal-links.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00 / 1,000 results

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

## SEO Broken Internal Links Checker

Checks a **small set of internal anchor links on one user-supplied public HTML page**, for independent site owners, content editors, and SEO auditors. This Actor does one job: test a bounded sample of same-host internal links for HTTP errors.

### What it does

Fetches one supplied page, reads `<a href>` URLs, resolves relative URLs (and same-page `<base href>`), removes fragments, deduplicates targets, and tests up to `maxLinks` links. Each target is checked with `HEAD`, falling back to `GET` when the server responds 403, 405, or 501. Robots.txt is respected for the source page and each tested target. Links outside the original hostname, including `www` variations, are not followed.

### Input example

```json
{"url": "https://www.python.org/", "maxLinks": 5}
```

`url` is required. `maxLinks` is a whole number from **1–30**, default 10. The Console prefill provides one URL. No sitemap, external domain crawling, login, search pages, browser rendering, or search-engine results are used.

### Output example (illustrative)

```json
{
  "sourceUrl": "https://example.org/guide",
  "targetUrl": "https://example.org/missing",
  "httpStatus": 404,
  "broken": true,
  "status": "broken",
  "error": null
}
```

Fields are always present: `sourceUrl` (string), `targetUrl` (string or null), `httpStatus` (integer or null, **final** HTTP status after permitted redirects), `broken` (true / false / null), `status` (`ok`, `broken`, `unverified`, `no_links`, `page_error`), `error` (plain-language string or null). HTTP >=400 is flagged `broken`; 2xx and other 3xx status codes are treated as reachable, while failures/robots-blocked targets are `unverified` with `broken=null` rather than falsely marked broken. This is HTTP-level availability, not proof that content is correct.

One record is emitted per distinct sampled internal target, in page order. A source that cannot be fetched produces one `page_error` record; a source with no eligible links produces one `no_links` record, both with `targetUrl=null`.

### Execution and dataset storage

- Apify cloud: `APIFY_TOKEN`, `ACTOR_DEFAULT_KEY_VALUE_STORE_ID`, and `ACTOR_DEFAULT_DATASET_ID` are used to read input and append output over the **Apify REST API**; no SDK or external Python dependencies.
- Locally: set `ACTOR_INPUT_JSON` or create `storage/key_value_stores/default/INPUT.json`, then run `python src/main.py`. Output is numbered JSON files under `storage/datasets/default/` (or `APIFY_LOCAL_STORAGE_DIR/datasets/default/`).
- Docker: `docker build -t seo-broken-internal-links .` and `docker run --rm -e ACTOR_INPUT_JSON='{"url":"https://www.python.org/","maxLinks":5}' seo-broken-internal-links`. Volume-mount storage if local results must persist.

### Limits and safeguards

- Exactly one source page, up to 30 distinct internal targets, each HTTP request capped at 1 MB and timed out at 8 seconds. One target may involve HEAD plus GET fallback. robots.txt fetches capped at 250 KB, cached per origin. Max 3 same-host redirects; HTTPS-to-HTTP redirects are refused.
- Internal means **same exact hostname** as supplied input; cross-host redirects are not followed. Query strings are preserved, fragments removed. Non-HTTP schemes and fragment-only links are skipped. Only links on the input page are checked; this is **not** a site-wide crawler.
- Public HTTP(S) only; private/local/reserved IPs refused by default. DNS pre-check does not fully eliminate DNS-rebinding risks. robots.txt uses stdlib `urllib.robotparser` with incomplete support for modern directives. 404/410 robots.txt is treated as absent; other robots errors fail closed (401/403 disallow). No browser-rendered links, JavaScript, CSS, authenticated content, or server-side hidden link discovery.
- 403, 429, and 5xx can be transient or access-policy effects; a flagged link is an HTTP result, not a guarantee the destination is permanently gone. HEAD/GET differences may occur.
- `ACTOR_TEST_ALLOW_LOOPBACK=1` is only for the localhost test fixture; do not enable it on Apify.

### Declared category recommendations (not Store-configured)

`SEO tools` · `Website monitoring` · `Developer tools` (3 categories).

### Suggested pricing (not configured)

**Pay per run: USD $0.02 per completed run** (up to 30 tested links). Proposed pricing only; nothing has been published or billed.

### Reproducible verification

```sh
python tests/run_smoke.py
python -m unittest discover -s tests -v
```

Both scripts launch `python src/main.py` as a separate process, passing a valid `ACTOR_INPUT_JSON` and using a local HTTP test fixture with the test-only loopback environment flag. Smoke output, input, and produced dataset item(s) are saved to `tests/evidence/`. No import-only verification is used.

# Actor input Schema

## `url` (type: `string`):

Public HTML page to extract internal links from.

## `maxLinks` (type: `integer`):

Number of distinct internal links to test; limited to 30.

## Actor input object example

```json
{
  "url": "https://www.python.org/",
  "maxLinks": 10
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# 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 = {
    "url": "https://www.python.org/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/seo-broken-internal-links").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 = { "url": "https://www.python.org/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/seo-broken-internal-links").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 '{
  "url": "https://www.python.org/"
}' |
apify call eichan/seo-broken-internal-links --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/seo-broken-internal-links"
        }
    }
}
```

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/tPFEveVnXTohjvSEH/builds/pi1NWoUXyaBGKblIz/openapi.json
