# Seo Heading Structure Checker (`eichan/seo-heading-structure-checker`) Actor

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

## Pricing

$0.01 / actor start

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 Heading Structure Checker

Checks H1–H6 heading order on **1–5 user-supplied public HTML pages**. Designed for SEO analysts, site owners, and content editors doing a quick structural audit.

### What it does

Fetches each supplied page (including a same-host redirect), honors `robots.txt`, extracts headings in document order, and reports missing/multiple H1s, an initial heading other than H1, skipped downward heading levels, and empty headings. Every input URL yields exactly one dataset item, even if the fetch fails. Text within headings is whitespace-normalized. The Actor does not inspect rendered JavaScript content.

### Input example

```json
{"urls": ["https://example.com/"]}
```

Input `urls` is required, with 1–5 HTTP(S) URLs. Prefill uses **one** URL. No login, cookies, search results, search scraping, pagination, or domain discovery.

### Output example (illustrative)

```json
{
  "url": "https://example.com/article",
  "headings": [{"level": "H1", "text": "Guide"}, {"level": "H3", "text": "Details"}],
  "h1Count": 1,
  "skippedLevels": [{"from": "H1", "to": "H3"}],
  "issues": ["Heading level jumps from H1 to H3."],
  "status": "issues_found",
  "error": null
}
```

Fields are always present: `url` (string), `headings` (array of `{level,text}`), `h1Count` (integer), `skippedLevels` (array of `{from,to}`), `issues` (array of strings), `status` (`ok`, `issues_found`, or `error`), `error` (string or null). When `status=error`, headings are empty and the plain-language cause is in `error`.

### Execution and dataset storage

- Apify cloud: configure `APIFY_TOKEN`, `ACTOR_DEFAULT_KEY_VALUE_STORE_ID`, and `ACTOR_DEFAULT_DATASET_ID` (the platform supplies these). The code reads `INPUT` via the Apify REST API and appends records to the default dataset. **No Apify SDK** is imported.
- Locally: set `ACTOR_INPUT_JSON` to a JSON string, or create `storage/key_value_stores/default/INPUT.json`; run `python src/main.py`. Dataset items are written as numbered JSON files under `storage/datasets/default/` (or `APIFY_LOCAL_STORAGE_DIR/datasets/default/`).
- Docker: `docker build -t seo-heading-structure-checker .`; to run with an input JSON environment variable, use `docker run --rm -e ACTOR_INPUT_JSON='{"urls":["https://example.com/"]}' seo-heading-structure-checker`. Local output stays in the container unless storage is volume-mounted.

### Limits and safeguards

- At most 5 pages per run, 1 MB downloaded per page, and 150 headings returned per page (the H1 count and checks still consider all parsed headings).
- Maximum 3 redirects, all same hostname; HTTPS-to-HTTP downgrade is refused. Responses have an 8-second timeout each. robots.txt lookup is capped at 250 KB and checked first; HTTP robots errors fail closed except 404/410 (treated as absent). Python's `urllib.robotparser` supports a subset of modern robots directives.
- Only HTTP(S) public hostnames/IPs. Local/private/reserved addresses are refused by default. DNS is checked before requests but DNS rebinding is not cryptographically prevented. No JavaScript rendering, CSS layout/visibility analysis, schema parsing, or WCAG compliance certification.
- An `ACTOR_TEST_ALLOW_LOOPBACK=1` **test-only** environment override permits localhost fixtures; do not configure this in production.
- Parsing may miss headings introduced by client-side JavaScript or atypical malformed HTML. No headless browser or dependencies.

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

`SEO tools` · `Marketing` (2 categories).

### Suggested pricing (not configured)

**Pay per run: USD $0.01 per completed run** (up to five URLs). This is a recommendation only; no billing has been configured or published.

### Reproducible verification

From this folder:

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

`tests/run_smoke.py` runs **`python src/main.py` as a subprocess** with a valid `ACTOR_INPUT_JSON` and a local HTTP fixture server. It writes the actual stdout, dataset records, and input used to `tests/evidence/`. The fixture uses the test-only loopback override. `tests/test_actor.py` also uses script-mode subprocesses; it does not import the Actor for its behavioral tests.

# Actor input Schema

## `urls` (type: `array`):

One to five public HTML URLs to inspect.

## Actor input object example

```json
{
  "urls": [
    "https://example.com/",
    "https://www.wikipedia.org/"
  ]
}
```

# 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 = {
    "urls": [
        "https://example.com/",
        "https://www.wikipedia.org/"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/seo-heading-structure-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 = { "urls": [
        "https://example.com/",
        "https://www.wikipedia.org/",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("eichan/seo-heading-structure-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 '{
  "urls": [
    "https://example.com/",
    "https://www.wikipedia.org/"
  ]
}' |
apify call eichan/seo-heading-structure-checker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/seo-heading-structure-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/3YIQkHt7XWnhMjVAC/builds/5OfDchuIKWD1WADFn/openapi.json
