# Website Page Status Delta Watch (`practical_ai_lab_jp/pal-website-page-status-delta-watch`) Actor

Monitors HTTP status codes for a bounded sitemap sample of one public HTTPS site and reports newly failed, recovered and redirected pages since the previous run.

- **URL**: https://apify.com/practical_ai_lab_jp/pal-website-page-status-delta-watch.md
- **Developed by:** [Practical AI Lab](https://apify.com/practical_ai_lab_jp) (community)
- **Categories:** E-commerce, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 page change reporteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Website Page Status Delta Watch

Give it one public HTTPS site root. On the first run it records an HTTP status baseline for a bounded sample of the site's sitemap URLs. On every later run it reports only what changed: pages that **newly failed**, **recovered**, or **started redirecting**, each with the source URL and exact UTC timestamps of the previous and current check.

It is built for recurring monitoring (a scheduled Task), not for one-off crawling. A run that finds nothing new produces a single status record instead of a page list.

### What you get

- **Baseline run** (`BASELINE_CREATED`): records the sample, outputs one status record with status-code counts. No change records.
- **Later runs**: one `PAGE_CHANGE` record per changed page, or one `NO_CHANGES` status record.
- **Run summary** in the key-value store under `RUN_SUMMARY`, including up to 25 pages that are failing right now (useful after the first run).

#### Change types

| `changeType` | Meaning |
| --- | --- |
| `NEWLY_FAILED` | Previously OK or redirecting; now 4xx, 5xx or unreachable (after one retry for 5xx and network errors). |
| `RECOVERED` | Previously failing; now 2xx. |
| `NEWLY_REDIRECTED` | Previously not redirecting; now 301/302/303/307/308. |
| `REDIRECT_TARGET_CHANGED` | Still redirecting, but to a different target. |
| `REDIRECT_REMOVED` | Previously redirecting; now 2xx. |
| `STATUS_CHANGED` | Another status change, for example 404 to 410 or 200 to 204. |
| `FIRST_SEEN_FAILED` / `FIRST_SEEN_REDIRECTED` | The page was not in the stored baseline (new in the sitemap or newly sampled) and is already failing or redirecting. `isFirstSeen` is `true`. |

#### Run status values

`BASELINE_CREATED`, `NO_CHANGES`, `CHANGES_DETECTED`, and the error statuses `INVALID_INPUT`, `ROBOTS_BLOCKED`, `ROBOTS_UNAVAILABLE`, `NO_SITEMAP`, `SITEMAP_INVALID`, `SITEMAP_UNAVAILABLE`, `SITEMAP_EMPTY`, `SITE_THROTTLED`. Error runs never modify the stored baseline.

### Quick start

Copy this input. Replace the URL with a site you are allowed to monitor (the prefilled value is only a placeholder and is not guaranteed to expose a sitemap):

```json
{
    "startUrl": "https://crawlee.dev/",
    "maxPages": 50
}
```

1. Run it once. Expect `BASELINE_CREATED`.
2. Run it again later with the same input. Expect `NO_CHANGES` or a list of `PAGE_CHANGE` records.

#### Input

| Field | Default | Notes |
| --- | --- | --- |
| `startUrl` (required) | | Public HTTPS site root, e.g. `https://www.example.com/`. No path, query, credentials, custom port, IP address or local name. |
| `maxPages` | 50 | 1 to 200. Sample size including the start page. |
| `maxSitemapFiles` | 5 | 1 to 10. Bound on sitemap and sitemap-index files fetched. |
| `requestDelayMillis` | 500 | 250 to 5000. A larger `Crawl-delay` in robots.txt overrides it. |
| `resetBaseline` | false | Discards the stored baseline for the domain. |
| `stateStoreName` | `pal-page-status-baselines` | Named key-value store holding one baseline per domain. |

#### Example change record (format illustration, not a real run)

```json
{
    "recordType": "PAGE_CHANGE",
    "changeType": "NEWLY_FAILED",
    "domain": "www.example.com",
    "pageUrl": "https://www.example.com/pricing",
    "sitemapSource": "https://www.example.com/sitemap.xml",
    "previousStatusCode": 200,
    "currentStatusCode": 404,
    "previousCheckedAt": "2026-11-02T08:00:00Z",
    "checkedAt": "2026-11-03T08:00:00Z",
    "isFirstSeen": false
}
```

Export the dataset as JSON or CSV from the run's Storage tab. Records have flat fields suitable for spreadsheets.

### Scheduling

Create a Task with your input and attach a Schedule (daily is a reasonable start; more frequent runs multiply requests to the site). Keep the default `stateStoreName`: a run's default key-value store is new for every cloud run and would lose the baseline, so the baseline lives in a named store that persists between runs. Use the same `startUrl` host for every run you want compared; the baseline is keyed by domain. Setting `stateStoreName` to an empty string uses the run's default store and only compares runs that share it, which is mainly useful for local runs.

### Safety rules the Actor enforces

- Reads `robots.txt` first and fails closed: a 401/403, server error, network error or cross-origin redirect on robots.txt stops the run. Wildcard (`*`, `$`) and longest-match rules are honored, as is `Crawl-delay` up to 30 seconds.
- Only same-origin HTTPS URLs on port 443 are requested. Redirects are never followed for pages; for robots.txt and sitemaps only same-origin HTTPS redirects are followed (three hops).
- Hostnames are resolved and rejected if any address is private, loopback, link-local, reserved or multicast. The connection is pinned to the validated address.
- Sitemap files are size-limited, entity/DTD declarations are rejected, gzip expansion is capped, and index nesting and file counts are bounded.
- Pages are requested with `GET` but the body is never read or stored. Only status codes and redirect targets are recorded. Redirect targets are stored without query strings.
- Sitemap URLs that contain credentials or an at-sign (possible email addresses) are dropped. No contact details are collected. No login, no proxies.
- Error, baseline, no-change and early-stopped runs are never billed.

### Pricing event

The code defines one pay-per-event name, `page-change-reported`, charged once per `PAGE_CHANGE` record after the dataset write and baseline save succeeded, and only when the run completed without stopping early. No price or plan is configured in this repository.

### Limitations and sample-size caveats

- **This is a sample, not a site audit.** At most `maxPages` (200) URLs are checked per run, selected from at most 5,000 sitemap URLs. The sample is chosen by a stable hash so it stays mostly consistent between runs, but when a sitemap is larger than the sample, most pages are never checked. If the sitemap grows, new URLs can displace sampled ones; those appear as `FIRST_SEEN_*` only if failing or redirecting.
- **Sitemap-only discovery.** Pages that are not in a sitemap are not seen. Sites without a sitemap (or whose sitemap is blocked by robots.txt) get `NO_SITEMAP` or `SITEMAP_UNAVAILABLE` and no baseline. The start page is always checked.
- **Index limits.** With large sitemap indexes, only the first sitemap files (up to `maxSitemapFiles`) are read, so coverage can be biased towards the first listed files. `sitemapTruncated` and `sitemapFilesSkipped` report when this happens.
- **Status codes only.** Soft 404s (a 200 page that says "not found"), changed content, broken JavaScript rendering and slow pages are not detected.
- **Single point-in-time check from one location.** 5xx and network errors are retried once, but short outages, geo-blocking, bot protection and rate limiting can still produce false failures or misses. HTTP 429 is not treated as a change; three in a row stop the run.
- **Same-origin only.** `www.example.com` and `example.com` are different origins; a sitemap listing other hosts has those URLs ignored, and a site that redirects robots.txt or sitemaps to another host is refused.
- **Baseline retention.** At most 1,000 pages per domain are kept; the least recently checked are dropped first. Pages that drop out of the sample keep their last known entry until pruned.
- **Redirect targets** are reported without query strings, so a change that only affects a query string is not detected.
- **Gzip sitemaps** are supported within size limits; other compression formats are not.
- **Clock and timestamps** are UTC, taken from the Actor's host clock at the moment each page was checked, with one-second resolution.
- **DNS pinning** protects against rebinding between the check and the connection, but the Actor depends on the platform's network and resolver being trustworthy.
- Only run it against sites you are permitted to monitor, and keep schedules polite.

### Development

Tests are offline and use mocked HTTP only:

```
python -m unittest discover -s tests -t .
```

Source layout: `src/main.py` (Apify I/O, baseline store, charging), `src/monitor.py` (run orchestration and deltas), `src/robots.py`, `src/sitemap.py`, `src/http_client.py` (pinned HTTPS client), `src/urls.py`, `src/diff.py`, `src/config.py`.

# Actor input Schema

## `startUrl` (type: `string`):

Public HTTPS site root such as https://www.example.com/. No path, query, credentials or custom port. Replace the prefilled value with a site you are allowed to monitor.

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

Size of the sitemap sample, including the start page. Larger samples cover more of the site but take longer because requests are spaced out.

## `maxSitemapFiles` (type: `integer`):

Upper bound on sitemap and sitemap-index files fetched in one run.

## `requestDelayMillis` (type: `integer`):

Minimum pause between requests to the site. A larger Crawl-delay in robots.txt always wins.

## `resetBaseline` (type: `boolean`):

Discard the stored baseline for this domain and create a new one in this run.

## `stateStoreName` (type: `string`):

Named key-value store that keeps one baseline per domain between runs. Leave the default for scheduled runs. An empty value uses the run's default store, which does not persist between cloud runs.

## Actor input object example

```json
{
  "startUrl": "https://crawlee.dev/",
  "maxPages": 50,
  "maxSitemapFiles": 5,
  "requestDelayMillis": 500,
  "resetBaseline": false,
  "stateStoreName": "pal-page-status-baselines"
}
```

# Actor output Schema

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

Download rows from the latest run in JSON/CSV.

# 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 = {
    "startUrl": "https://crawlee.dev/",
    "maxPages": 50,
    "maxSitemapFiles": 5,
    "requestDelayMillis": 500
};

// Run the Actor and wait for it to finish
const run = await client.actor("practical_ai_lab_jp/pal-website-page-status-delta-watch").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 = {
    "startUrl": "https://crawlee.dev/",
    "maxPages": 50,
    "maxSitemapFiles": 5,
    "requestDelayMillis": 500,
}

# Run the Actor and wait for it to finish
run = client.actor("practical_ai_lab_jp/pal-website-page-status-delta-watch").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 '{
  "startUrl": "https://crawlee.dev/",
  "maxPages": 50,
  "maxSitemapFiles": 5,
  "requestDelayMillis": 500
}' |
apify call practical_ai_lab_jp/pal-website-page-status-delta-watch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,practical_ai_lab_jp/pal-website-page-status-delta-watch"
        }
    }
}
```

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/FjwgVh75ofzlnVuUc/builds/7sqDlmO2CPlrzgBkS/openapi.json
