# Product Rating Extractor (`eichan/product-rating-extractor`) Actor

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

## Product Rating Extractor

Read **one public product-like HTML page** and output the schema.org `Product` / `ProductGroup` `aggregateRating` published in its **JSON-LD**. One page per run; one dataset row. No storefront account, browser, paid APIs, or Apify SDK.

### Who is it for?

Store owners, catalog-quality analysts, and SEO practitioners who need a machine-readable snapshot of **declared structured rating data**. This does **not** verify genuine reviews or infer ratings from stars, page copy, or review widgets.

### Try the prefilled example

```json
{
  "productUrl": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html"
}
```

This is a **real, publicly accessible Apify-hosted HTML URL**, checked reachable on **2026-11-01**. Its publisher describes it as a **synthetic demonstration page** containing Product AggregateRating data with a **fictitious 4.5 rating**. **Not a real retailer and not authentic customer reviews.** Its availability/content is maintained by a third party and may change. The buyer should replace it with a permitted public merchant product page after trying the example.

The actual HTTP source HTML could not be fetched directly in the local Python container for this delivery. The public URL was checked through a web retrieval service and the publisher's description. The executable smoke evidence in `tests/` uses a separately labelled **local HTTP fixture**, not the live URL. Its count must **not** be presented as the count on the hosted page.

### Output example

Successful item from the **included synthetic local fixture** (illustrative, **not the live URL's actual review count**):

```json
{
  "url": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html",
  "ratingValue": 4.5,
  "reviewCount": 12,
  "ratingCount": null,
  "bestRating": 5.0,
  "status": "ok",
  "error": null
}
```

Fields are stable: `url` is the supplied URL; `ratingValue` and `bestRating` are JSON numbers or `null`; `reviewCount` and `ratingCount` are nonnegative integers or `null`. `bestRating` remains `null` when unspecified: **no assumed five-star scale**. At least `ratingValue` and one of `reviewCount` or `ratingCount` must be present as clean numbers.

If the page lacks complete Product AggregateRating JSON-LD, the Actor still writes **one plain-language error item** instead of guessing:

```json
{
  "url": "https://www.allbirds.com/products/mens-wool-runners",
  "ratingValue": null,
  "reviewCount": null,
  "ratingCount": null,
  "bestRating": null,
  "status": "error",
  "error": "No complete Product AggregateRating exists in the page JSON-LD (ratingValue and a count required)."
}
```

The above error is an **example of the error shape**, not a statement about the currently published Allbirds page.

### What it does (and does not do)

1. Validates your one HTTPS URL and rejects private hosts, local services, nonstandard ports, redirects, Amazon and eBay.
2. Retrieves at most 2 MB of publicly accessible static HTML with a 15-second request timeout.
3. Examines `application/ld+json` script tags (up to 80), including `@graph` and `ProductGroup` / `Product` objects, for an `aggregateRating` object.
4. Writes one result to the Apify default dataset through the Apify REST API, or locally under `storage/datasets/default/`.

It **never** reads visible stars/text, microdata, HTML ratings, comments, login-protected data, or JavaScript-rendered review widgets. Malformed JSON-LD blocks are skipped. Multiple products are not scraped in bulk. A page without AggregateRating is not necessarily defective. It doesn't test Google rich-result eligibility or review authenticity. Connection failures are plain-language run errors without tracebacks. DNS checks reduce SSRF risk but are not a full defense against DNS rebinding. No redirects are followed.

### Run locally

Python 3.12+; no pip installation required.

```bash
cd product-rating-extractor
export ACTOR_INPUT_JSON='{"productUrl":"https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html"}'
python src/main.py
```

Or create `storage/key_value_stores/default/INPUT.json` with the input object and omit `ACTOR_INPUT_JSON`. The local Dataset item is written to `storage/datasets/default/000000001.json` (next unused number when running again).

On Apify, `INPUT` is read from default key-value storage and results are posted via the standard Dataset REST endpoint using `APIFY_DEFAULT_DATASET_ID` and `APIFY_TOKEN` provided by the runtime. No Apify SDK. Runtime storage permissions and network access are required.

### Reproduce tests and script-mode smoke evidence

```bash
python -m unittest discover -s tests -p 'test_*.py' -v
python tests/smoke.py
```

`tests/smoke.py` **executes `python src/main.py` in a subprocess**, passes the valid prefilled input via `ACTOR_INPUT_JSON`, injects a deliberately local HTTP mock via `tests/smoke_support/sitecustomize.py`, and verifies the JSON Dataset files. This is **not an import-only test**. It writes `tests/smoke_evidence.txt` and `tests/smoke_dataset.json`. On some managed Python environments it uses `/usr/bin/python3` via a temporary `python` PATH alias to ensure the test-only startup hook wins. There is **no real external HTTP call in the smoke run**.

### Store metadata and suggested pricing

- **Apify Store category:** `ECOMMERCE` (E-commerce). Suggested output-type tag: Reviews.
- **Suggested price:** **$3 per 1,000 successful rating results** ($0.003 per successful result); no charge suggested for `status=error` items. If configuring a built-in dataset-item event, carefully account for error rows when setting billing.
- The suggestion is also recorded in `store_metadata.json`. **No billing is configured. No Store publishing or Apify run was performed.**

# Actor input Schema

## `productUrl` (type: `string`):

A publicly accessible HTTPS HTML page with JSON-LD Product aggregateRating.

## Actor input object example

```json
{
  "productUrl": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html"
}
```

# 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 = {
    "productUrl": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/product-rating-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 = { "productUrl": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/product-rating-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 '{
  "productUrl": "https://api.apify.com/v2/key-value-stores/DHMHtotPcN9CAKXYj/records/complete.html"
}' |
apify call eichan/product-rating-extractor --silent --output-dataset

```

## MCP server setup

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