# Webpage Hash Snapshot (`eichan/webpage-hash-snapshot`) Actor

- **URL**: https://apify.com/eichan/webpage-hash-snapshot.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

$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

## Webpage Content Hash Snapshot

Fetch **one** public HTML page, extract its non-hidden static text, normalize whitespace, and generate a deterministic SHA-256 fingerprint. Schedule it repeatedly to capture one clean content snapshot per run.

### Who it is for

Site owners, release watchers, researchers, and operations teams who want simple snapshots of publicly visible HTML text without writing a site-specific scraper.

### Input example

```json
{
  "url": "https://example.com/"
}
```

To compare against a previous run, provide its exact `contentHash`:

```json
{
  "url": "https://example.com/",
  "previousHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
```

| Field | Required | Description |
| --- | --- | --- |
| `url` | Yes | One public HTML URL. The form prefills **one page**. |
| `previousHash` | No | A previous run's 64-character SHA-256 hex digest. |

### Output example

One dataset row per successful run (hash shown is illustrative):

```json
{
  "url": "https://example.com/",
  "contentHash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  "textLength": 125,
  "changed": null,
  "checkedAt": "2026-11-01T04:00:00Z"
}
```

- `url`: the input URL.
- `contentHash`: lowercase SHA-256 hash of the normalized UTF-8 text.
- `textLength`: Unicode character count of that same normalized text.
- `changed`: `true` or `false` if `previousHash` was supplied; otherwise **`null`**, meaning *not compared*.
- `checkedAt`: UTC timestamp captured at run start.

### How hashing works

1. Download the HTML with one HTTP(S) GET request, following public HTTP(S) redirects.
2. Decode using the declared response charset, falling back to UTF-8.
3. Parse static HTML text, skipping scripts, styles, head metadata, templates, SVG, `noscript`, and explicitly hidden elements.
4. Collapse whitespace runs to single spaces, then hash the resulting text as UTF-8 bytes.

For an unchanged response, the normalized content should produce the same hash. Dynamic banners, timestamps, navigation, and other visible content can still create legitimate differences even when the primary article has not changed.

### Scheduling use case

Schedule once a day to collect a historical series of content hashes. A separate automation can read the last run's `contentHash`, pass it back as `previousHash`, and respond when the new output has `changed: true`. **Scheduling alone does not automatically retrieve previous run state**; without the comparison value, `changed` is always `null`.

### Limits and behavior

- One HTML page per run; **2 MB** maximum downloaded HTML, **20-second** request timeout.
- Public IP destinations and standard HTTP(S) ports 80/443 only; local/private-network URLs are rejected.
- No login, cookies, proxy service, browser, JavaScript execution, PDF extraction, CSS layout engine, or external API keys.
- The parser uses HTML tag/inline-hidden heuristics; it cannot fully apply external CSS, compute visibility, render JavaScript-only pages, or read shadow DOM.
- If the HTML is empty/non-HTML or contains no extractable text, the run fails with a simple error rather than emitting a misleading empty fingerprint.
- No multi-page crawling, persistent cross-run state, or automatic alerts. Some public sites block data-center IPs or change visible nonessential text frequently.
- Failed runs print plain-English `ERROR:` messages and exit unsuccessfully, without tracebacks.
- The platform supplies its own run storage token; it is used only to read the Actor's own input and write its default dataset, with no user-supplied token.

### Run / deploy

**Cloud:** Upload this entire folder as one Apify Actor project, build, and run via the Console-generated input form. Cloud storage uses the built-in Python `urllib` library with Apify-provided environment variables; the Apify SDK is not installed.

**Local:** Create `storage/key_value_stores/default/INPUT.json` with the example input and run:

```bash
python src/main.py
```

The result appears in `storage/datasets/default/` as an indexed JSON file. For Docker use, mount a local `storage/` directory if running outside the Apify platform.

### Store placement / pricing suggestion

- **Category:** Automation (primary)
- **Additional category:** Developer tools
- **Suggested monetization:** Pay per event, **per Actor run** (e.g. provisional **$0.003/run** `actor-start` event), because each successful run produces one fingerprint. Confirm real unit economics before release.
- **Billing status:** The Actor **does not currently charge PPE events**; this is an intended pricing model, not an implemented billing feature. Wire/test the Apify event charge separately before paid publication, or initially use pay-per-usage.

# Actor input Schema

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

One public HTTP(S) HTML page URL.

## `previousHash` (type: `string`):

The contentHash returned by an earlier run. If omitted, changed is null.

## Actor input object example

```json
{
  "url": "https://example.com/"
}
```

# 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://example.com/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/webpage-hash-snapshot").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://example.com/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/webpage-hash-snapshot").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://example.com/"
}' |
apify call eichan/webpage-hash-snapshot --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/webpage-hash-snapshot"
        }
    }
}
```

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/s67712SXyDhTTVPXE/builds/QwEabl4K46IiZlAmK/openapi.json
