# Faq Jsonld Extractor (`eichan/faq-jsonld-extractor`) Actor

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

$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

## FAQ JSON-LD Extractor

**One job:** fetch one publicly accessible HTML page, look for `FAQPage` JSON-LD structured data, and save each **actually declared** question and accepted answer as one dataset row. No AI is involved.

### Who it is for

Developers, content auditors, documentation maintainers and RAG data-preparation pipelines that need already-published structured FAQ content in two plain-text columns.

### How it works (and what it does not do)

1. Check the supplied URL is HTTP(S), resolves to public IP addresses and has no login credentials. Only the standard HTTP/HTTPS ports are allowed.
2. Check that page access is allowed by the host's `robots.txt`. Make a single page request, with a descriptive User-Agent and short timeouts. Only same-host, same-scheme redirects are permitted. The HTML download is capped at 1 MB; no JavaScript runs.
3. Parse HTML `<script type="application/ld+json">` blocks, including top-level arrays and `@graph`. Find objects with `@type: FAQPage`, then `mainEntity` `Question` nodes containing a nonempty `name` and `acceptedAnswer.text`.
4. Remove HTML tags from questions and answers, decode HTML entities and collapse whitespace. Keep source ordering; skip incomplete pairs and exact duplicates. Save up to `maxPairs` (default 50, maximum 100).

**No matching pair:** an ordinary dataset row with `status: "error"`, a plain-language `error`, and null `question`/`answer` is written. This is not a fabricated FAQ. Invalid input or blocked/failed fetch instead produces a plain-language terminal error and nonzero exit code.

### Example input (one real public URL)

The input-schema prefill uses **httpbin.org's public base64 endpoint**. It serves a small HTML fixture containing one genuine `FAQPage` JSON-LD script. This synthetic demonstration is a real HTTP endpoint, not a nonexistent placeholder and not a claim about a third-party site's FAQ quality. The URL is long because it encodes the sample HTML.

You can paste this exact prefilled input, or use `tests/sample_input.json`:

```json
{
  "url": "https://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg==",
  "maxPairs": 50
}
```

### Example output (one dataset row)

```json
{
  "status": "ok",
  "source_url": "https://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg==",
  "position": 1,
  "question": "What is JSON-LD?",
  "answer": "JSON structured data.",
  "error": null
}
```

`source_url` always contains the full original URL (except any fragment, which is not sent to the website).

**No data output example:**

```json
{
  "status": "error",
  "source_url": "https://example.org/page-without-faq-data",
  "position": null,
  "question": null,
  "answer": null,
  "error": "No FAQPage JSON-LD with complete questions and accepted answers was found on this page."
}
```

### Input fields

| Field | Required | Meaning |
| --- | --- | --- |
| `url` | Yes | One publicly reachable `http://` or `https://` page, max 2,048 characters. |
| `maxPairs` | No | Maximum output Q\&A items, 1–100; default 50. |

Each success dataset item has fixed keys: `status`, `source_url`, `position`, `question`, `answer`, `error`.

### Limits and cautions

- Extracts **only** JSON-LD FAQPage; ignores visually apparent FAQs, microdata, RDFa, QAPage and schema created by client-side JavaScript.
- No translation, question generation, answer correctness assessment, legal or medical judgment, or guaranteed completeness.
- Malformed JSON-LD and incomplete pairs are skipped, not guessed. JSON-LD can be outdated or disagree with what a visitor sees.
- Does not follow page links; does not log in or bypass access restrictions; blocks non-public/local IPs. The public DNS check is a safety filter but cannot guarantee protection against all DNS rebinding scenarios.
- Some sites block automated clients or disallow access in `robots.txt`; others may change or remove structured data. The public demonstration endpoint is maintained by a third party.
- HTML parsing is rule-based and may not handle every nonstandard script encoding. Supported content types: HTML, XHTML or raw HTML sent as text/plain.
- One page download, max 1 MB, short timeouts; `robots.txt` is fetched separately to respect the site's policy.

### Run locally and test

Python 3.12+; **no pip dependencies** and **no Apify SDK**.

```bash
## From this Actor's root folder, use the actual prefilled URL:
mkdir -p storage/key_value_stores/default
cp tests/sample_input.json storage/key_value_stores/default/INPUT.json
python src/main.py
python -m unittest discover -s tests -v
```

For the **complete working URL**, use `tests/sample_input.json` as `storage/key_value_stores/default/INPUT.json`, or copy the exact prefill from `input_schema.json`. To replay the offline script-mode smoke (it simulates the website HTTP response, so network access is not required):

```bash
python tests/run_smoke.py
## Under the hood it invokes: python src/main.py
```

The smoke runner passes the exact JSON of `tests/sample_input.json` via `ACTOR_INPUT_JSON`. It calls `python src/main.py` using the system Python in this test environment; `tests/sitecustomize.py` simulates HTTP only while `FAQ_OFFLINE_SMOKE=1` is set, and is **not** part of the Docker image. The runner records the actual terminal output and dataset rows in `tests/smoke_*`.

On Apify, runtime input and output use its documented REST storage API with the platform-provided token; locally, items go to `storage/datasets/default/000000001.json` etc. Only internal Apify storage uses a token; **users provide no API keys**.

### Store listing and suggested price

- Intended category: **AI** (data preparation, not generative AI).
- Suggested pricing: **$0.001 per successful extracted Q\&A item**; zero billable success items for a `status: error` row. This is only a commercial suggestion, **not configured**; publishing and billing are not part of the deliverable.
- Structured suggestion: `store_metadata.json`.

### Test provenance

The script-mode FAQ smoke uses the true production entry point and real dataset writer but **offline mocked HTTP** because direct external DNS is unavailable in the packaging environment. An independent public fetch confirmed the httpbin example URL responds with the encoded sample content; no actual Apify deployment or Docker build was performed. Read `tests/smoke_evidence.txt` and run `python tests/run_smoke.py` to reproduce.

# Actor input Schema

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

Public httpbin base64 endpoint serving a tiny, deterministic HTML page with one FAQPage JSON-LD question.

## `maxPairs` (type: `integer`):

Maximum number of Q\&A pairs to output (1–100).

## Actor input object example

```json
{
  "url": "https://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg==",
  "maxPairs": 50
}
```

# 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://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg=="
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/faq-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://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg==" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/faq-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://httpbin.org/base64/PGh0bWw+PHNjcmlwdCB0eXBlPSJhcHBsaWNhdGlvbi9sZCtqc29uIj57IkB0eXBlIjoiRkFRUGFnZSIsIm1haW5FbnRpdHkiOlt7IkB0eXBlIjoiUXVlc3Rpb24iLCJuYW1lIjoiV2hhdCBpcyBKU09OLUxEPyIsImFjY2VwdGVkQW5zd2VyIjp7IkB0eXBlIjoiQW5zd2VyIiwidGV4dCI6IkpTT04gc3RydWN0dXJlZCBkYXRhLiJ9fV19PC9zY3JpcHQ+PC9odG1sPg=="
}' |
apify call eichan/faq-jsonld-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/faq-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/X2ZstVGwmnpRhJk5w/builds/cxftXfzcPBAYIZw9K/openapi.json
