# Seo Jsonld Extractor (`eichan/seo-jsonld-extractor`) Actor

- **URL**: https://apify.com/eichan/seo-jsonld-extractor.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

## JSON-LD Block Extractor

### What it does

Fetches one page and extracts **every** HTML `<script type="application/ld+json">` block in document order, returning one dataset item per block. It retains the exact parsed JSON value in `data`, and gathers the actual `@type` string values found anywhere in that value. Malformed JSON becomes its own item with a readable `parseNote`; later blocks are still processed.

### Who it is for

SEO auditors, structured-data maintainers, site owners, and developers checking what JSON-LD a page actually embeds.

### Input

Supply **one** publicly reachable HTTP/HTTPS URL (no account or API key):

```json
{
  "url": "https://yoast.com/author-publisher-entities-seo/"
}
```

This is also the prefilled Store example; it is a real public page. It may change after publication. The only configurable field is `url`. The Actor will request the target site’s `/robots.txt` and, if permitted, fetch the page itself.

### Output

`sourceUrl` (string or null on invalid input), `blockIndex` (1-based integer or null), `types` (list of discovered `@type` strings), `data` (parsed JSON value or null), `status` (`ok`, `malformed`, `no_jsonld`, or `error`), `parseNote` (string or null), `error` (string or null).

Example actual dataset item, recorded by the included local script-mode smoke test (the `127.0.0.1` address is a disposable test fixture, **not** the public prefill):

```json
{
  "sourceUrl": "http://127.0.0.1:43373/page",
  "blockIndex": 1,
  "types": [
    "Article",
    "Person"
  ],
  "data": {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "Article",
        "headline": "Test post"
      },
      {
        "@type": "Person",
        "name": "Eichan"
      }
    ]
  },
  "status": "ok",
  "parseNote": null,
  "error": null
}
```

The script-mode fixture includes one valid JSON-LD `@graph` and one malformed JSON-LD block, producing two records. See `tests/evidence/smoke_dataset.json` for **all** actual smoke-test records, including malformed JSON-LD when applicable.

### How to run

On Apify, paste the URL in the input form and run the Actor. The input is loaded in this exact precedence order:

1. Parse `ACTOR_INPUT_JSON` if set (including when it contains invalid JSON; no silent fallback).
2. Otherwise use `GET https://api.apify.com/v2/key-value-stores/{APIFY_DEFAULT_KEY_VALUE_STORE_ID}/records/INPUT` with `Authorization: Bearer {APIFY_TOKEN}` when the default key-value store ID exists.
3. Otherwise read `./storage/key_value_stores/default/INPUT.json` relative to the process working directory.

On Apify, results are appended to the default dataset by an authorized REST API `POST`. Locally, one JSON file per item appears under `storage/datasets/default/`.

To run locally from this Actor folder:

```bash
export ACTOR_INPUT_JSON='{"url": "https://yoast.com/author-publisher-entities-seo/"}'
python src/main.py
```

Or put the same JSON in `storage/key_value_stores/default/INPUT.json` and run `python src/main.py` with `ACTOR_INPUT_JSON` unset. Only Python 3.12+ standard-library modules are required.

To rerun verifiable offline tests:

```bash
python -m unittest discover -s tests -p test_actor.py -v
python tests/run_smoke.py
```

The smoke runner launches a local HTTP fixture and executes **`python src/main.py` as a subprocess** with a valid `ACTOR_INPUT_JSON`. It writes the full terminal output, valid input, and produced dataset records to `tests/evidence/`. `ACTOR_TEST_ALLOW_LOOPBACK=1` is only set by this local test runner, never by default.

### Limits and error handling

It reads **server-returned HTML only**, without running JavaScript. JSON-LD added by client-side scripts is not included. It does not follow `src` attributes, external URLs, or validate schema.org semantics or Google rich-results eligibility. A page with zero JSON-LD blocks produces one `no_jsonld` item, rather than an empty dataset. Block indexes start at 1 and duplicate blocks are preserved. Malformed JSON is not repaired or inferred.

- One page per run. No general crawling, search-result scraping, login, or third-party Python packages.
- Two HTTP requests maximum in a normal run (robots.txt and the page), with at most three same-host redirects for each request. The page is limited to 2 MB; robots.txt is limited to 200 KB; each request has a 12-second timeout.
- By default, local/private/reserved IP addresses and nonstandard ports are rejected; cross-host redirects are rejected. The actor checks DNS addresses but is **not** a hardened defence against DNS rebinding on hostile hostnames. Use only public sites you are authorized to inspect.
- Robots.txt opt-outs are respected; missing robots.txt (404/410) is allowed. If the page cannot be fetched, or input is invalid, the Actor writes a stable `error` dataset record and prints a short message, not a traceback. A failed run may exit nonzero even if its error item is written.
- Web content, robots policies, and site availability change. The public example is not part of the offline unit/smoke fixture, so cloud execution must be checked after deploying.

### Suggested Store categories and pricing

**Categories:** SEO tools, Developer tools, Marketing.

Suggested **$0.01 per run**, independent of the number of blocks. This is a proposed Store price only; no monetization or billing is configured.

### Deployment state

Source-only deliverable, not published. No Apify cloud runs or billing configuration have been performed.

# Actor input Schema

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

One public HTTP or HTTPS page URL to inspect. No authentication or site crawling.

## Actor input object example

```json
{
  "url": "https://yoast.com/author-publisher-entities-seo/"
}
```

# 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://yoast.com/author-publisher-entities-seo/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/seo-jsonld-extractor").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://yoast.com/author-publisher-entities-seo/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/seo-jsonld-extractor").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://yoast.com/author-publisher-entities-seo/"
}' |
apify call eichan/seo-jsonld-extractor --silent --output-dataset

```

## MCP server setup

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

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/y1SfxyUS0zKdSwcu2/builds/jJ943oo3uIChbeYrP/openapi.json
