# WNC Weekly Ad Offer Collector (`meaningful_permafrost/my-actor`) Actor

Collects coupon and sale offers from weekly-ad pages you list and rewrites them in a standard form (sale price, dollar off, percent off, BOGO, multi-buy, spend-and-save) with expiry dates, ready for price comparison.

- **URL**: https://apify.com/meaningful_permafrost/my-actor.md
- **Developed by:** [Adam Miller](https://apify.com/meaningful_permafrost) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## 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

## WNC Weekly Ad Offer Collector

This Actor collects coupon and sale offers from weekly-ad pages that you list, rewrites each offer in a standard form, and saves the results for comparison. It was built for comparing grocery and retail deals across stores in western North Carolina, but it works on any weekly-ad page where offers appear as text.

### What it produces

- **Offers (dataset):** one row per offer, with the store, offer type, normalized text, expiry date, the raw text it came from, the page URL, and a `needsReview` flag.
- **Offers ready to import (key-value store record `OFFERS_IMPORT`):** a JSON array of normalized, unexpired offers with `text`, `appliesTo`, and `expires` fields.

### Before you run it

Only add pages whose terms of use allow automated access. Many retailer sites prohibit scraping, and many load their weekly ads from third-party circular services with their own terms. The Actor respects robots.txt by default.

### Input

| Field | Purpose |
|---|---|
| `stores` | Required. A list of pages to collect. Each entry has `url` (required), `storeName`, `chain`, `town`, and optionally `appliesTo`. |
| `renderJavaScript` | Use a browser for pages that load offers with JavaScript. This option is slower and uses more compute. |
| `waitForSelector` | In browser mode, a CSS selector to wait for before reading the page. |
| `selectors` | Optional CSS selectors for more accurate extraction: `item`, `title`, `price`, `details`, `expires`. Leave this empty to use automatic detection. |
| `followLinkGlobs` and `maxDepth` | Follow additional pages, such as ad page 2, that match the given patterns. |
| `maxRequestsPerCrawl` | The maximum number of pages loaded in one run. |
| `defaultValidDays` | The expiry used when neither the offer nor the page states an end date. |
| `respectRobotsTxt` | Skip pages that robots.txt disallows. This is on by default. |
| `proxyConfiguration` | Optional proxy settings. |

Example input:

```json
{
  "stores": [
    {
      "url": "https://www.example.com/weekly-ad",
      "storeName": "Example Grocery, Boone",
      "chain": "Example Grocery",
      "town": "Boone"
    }
  ],
  "selectors": { "item": ".offer-card", "title": ".offer-title", "price": ".offer-price" }
}
```

### How offers are normalized

| Type | Normalized form |
|---|---|
| Sale price | `Sale [item] $X` (with `/lb` when the price is per pound) |
| Dollar off | `$X off [item]` or `$X off [item] when you buy N` |
| Percent off | `N% off [item]` |
| BOGO | `BOGO [item]` |
| Multi-buy | `N for $X [item]` |
| Basket | `Spend $X get $Y off` |

The Actor looks for an expiry date in the offer first, then on the page (for example, "Prices valid 11/18 - 11/24"), and otherwise uses the default. The `expiresSource` field records which of the three it used. A row is flagged with `needsReview` when its type is unknown, when no item name could be found, or when the expiry is only the default.

### Limits

- Automatic detection works on pages where each offer appears as its own block of text. Image-only circulars, PDFs, and canvas-rendered flyers contain no readable offer text, so the Actor cannot extract offers from them.
- With automatic detection, item names can include extra description text. Supplying `selectors` for the item name and price gives cleaner results.
- Sites that block automated requests will return errors, and the Actor does not try to get around them.

# Actor input Schema

## `stores` (type: `array`):

One entry per page to collect. Fields: url (required), storeName, chain, town, appliesTo (optional id used in the import output; defaults to a slug of the chain name). Only add pages whose terms of use allow automated access.

## `renderJavaScript` (type: `boolean`):

Turn on for weekly-ad pages that load offers with JavaScript. Slower and uses more compute units.

## `waitForSelector` (type: `string`):

CSS selector that appears once offers have loaded, for example .offer-card. Leave empty to skip.

## `selectors` (type: `object`):

If you know the page structure, give selectors for more accurate results: item (one offer card), title, price, details, expires. Selectors other than item are searched inside each item. Leave empty to use automatic detection.

## `followLinkGlobs` (type: `array`):

Glob patterns for additional pages to collect from the same store, such as ad page 2 or category pages. Example: https://www.example.com/weekly-ad/\*\*

## `maxDepth` (type: `integer`):

How many links away from each starting page to follow when patterns are given. 0 collects only the starting pages.

## `maxRequestsPerCrawl` (type: `integer`):

Hard limit on the number of pages loaded in one run.

## `defaultValidDays` (type: `integer`):

Used as the expiry when neither the offer nor the page states an end date.

## `respectRobotsTxt` (type: `boolean`):

Skip pages that the site's robots.txt disallows.

## `proxyConfiguration` (type: `object`):

Optional proxy settings.

## Actor input object example

```json
{
  "stores": [
    {
      "url": "https://www.example.com/weekly-ad",
      "storeName": "Example Grocery, Boone",
      "chain": "Example Grocery",
      "town": "Boone"
    }
  ],
  "renderJavaScript": false,
  "waitForSelector": "",
  "selectors": {},
  "followLinkGlobs": [],
  "maxDepth": 0,
  "maxRequestsPerCrawl": 100,
  "defaultValidDays": 7,
  "respectRobotsTxt": true,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `offers` (type: `string`):

One row per offer found, with normalized text, expiry, and a needs-review flag.

## `offersImport` (type: `string`):

Normalized, unexpired offers in the format the WNC Deal Finder prototype imports.

# 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 = {
    "stores": [
        {
            "url": "https://www.example.com/weekly-ad",
            "storeName": "Example Grocery, Boone",
            "chain": "Example Grocery",
            "town": "Boone"
        }
    ],
    "selectors": {},
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("meaningful_permafrost/my-actor").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 = {
    "stores": [{
            "url": "https://www.example.com/weekly-ad",
            "storeName": "Example Grocery, Boone",
            "chain": "Example Grocery",
            "town": "Boone",
        }],
    "selectors": {},
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("meaningful_permafrost/my-actor").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 '{
  "stores": [
    {
      "url": "https://www.example.com/weekly-ad",
      "storeName": "Example Grocery, Boone",
      "chain": "Example Grocery",
      "town": "Boone"
    }
  ],
  "selectors": {},
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call meaningful_permafrost/my-actor --silent --output-dataset

```

## MCP server setup

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

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/QO3C6Amupc2YbCK21/builds/bnqdauXLHACxC91u3/openapi.json
