# Sitemap Product Url Collector (`eichan/sitemap-product-url-collector`) Actor

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

$2.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

## Sitemap Product URL Collector

Find a **small, bounded list of likely product-page URLs** from exactly one public XML sitemap or a sitemap index. Returns **one dataset item per matching URL**, without opening product pages or visiting unrelated sites.

### Who is it for?

E-commerce catalog teams, feed validators, and store owners who need a lightweight list of `/product/` or `/products/` paths for a site they are permitted to inspect. It does **not** verify that each URL resolves to a currently purchasable product.

### Try the prefilled example

```json
{
  "sitemapUrl": "https://www.allbirds.com/sitemap.xml",
  "maxUrls": 5
}
```

This is a **real public Shopify sitemap index**, independently retrieved on **2026-11-01**. Its product child sitemap was also checked to contain URLs like `https://www.allbirds.com/products/mens-wool-runners`. No placeholder URLs are used. The external site may change its sitemap at any time and could restrict automated access.

### Output example

Two items from the **included local synthetic sitemap fixture** (illustrative timestamps, not live crawl measurements):

```json
[
  {
    "url": "https://www.allbirds.com/products/mens-wool-runners",
    "lastmod": "2026-10-22T12:00:00+00:00",
    "sourceSitemap": "https://www.allbirds.com/sitemap_products_1.xml?from=1878193471557&to=7369944137808"
  },
  {
    "url": "https://www.allbirds.com/products/womens-wool-runners-natural-black",
    "lastmod": null,
    "sourceSitemap": "https://www.allbirds.com/sitemap_products_1.xml?from=1878193471557&to=7369944137808"
  }
]
```

Each item always has exactly these three fields. `lastmod` is the **raw XML `<lastmod>` string**, or `null` if absent. `sourceSitemap` is the exact child sitemap that supplied the URL, or the starting URL for a plain `urlset`.

### How it works

1. Validates one public HTTPS sitemap URL and resolves its public IP; refuses private/non-public hosts, redirects, custom HTTPS ports, Amazon/eBay, and cross-host child sitemaps.
2. Parses a standard `<urlset>` directly, or follows a **single** `<sitemapindex>` level, inspecting up to **20 same-host child sitemaps** in document order.
3. Supports public `.xml`, `.xml.gz`, and gzip-compressed responses. Compression is detected by extension, headers, or gzip magic bytes.
4. Keeps only absolute same-host HTTPS entries with a path containing **`/product/` or `/products/` followed by content** (case-insensitive). Duplicates are removed and URLs are capped at `maxUrls`.
5. Saves the resulting rows to the default Apify Dataset through REST, or to numbered local Dataset JSON files.

### Honest limits

- **One sitemap URL per run.** `maxUrls` defaults to 5; allowed 1–100. No site-wide discovery and no `robots.txt` search. No nested index traversal beyond **one level**.
- Maximum 20 child sitemap files; 15-second timeout per request; **2 MB download** and **4 MB uncompressed XML** per file. Delays of 0.2 seconds between child requests. No concurrent crawling, retry flood, or browser automation.
- Only exact URL path segments `/product/` and `/products/` qualify. Product pages with other URL structures (e.g. `/shop/`, `/store/`, `/p/`) are intentionally omitted. A matching path is **not a verified product**.
- Follows same-host sitemap URLs only; does not fetch any product pages. Skips cross-host or malformed child sitemaps with plain-language notices. When nothing matches, returns an empty dataset and logs why.
- Rejects DTD/ENTITY-containing XML. Public sitemap owners may change URLs, rate-limit, or block requests. DNS checks reduce SSRF risk but not every DNS rebinding scenario.

### Run locally

Python 3.12+; no external packages.

```bash
cd sitemap-product-url-collector
export ACTOR_INPUT_JSON='{"sitemapUrl":"https://www.allbirds.com/sitemap.xml","maxUrls":5}'
python src/main.py
```

Or save the same JSON in `storage/key_value_stores/default/INPUT.json` and omit `ACTOR_INPUT_JSON`. Local output is one JSON file per dataset item in `storage/datasets/default/`. On Apify, runtime dataset IDs and token are used for REST dataset writes without any SDK.

### Reproduce tests and script-mode smoke evidence

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

The smoke script runs **`python src/main.py` as a subprocess** with a valid prefilled input and uses test-only `sitecustomize.py` to serve deterministic local XML fixtures. It captures the terminal output and resulting Dataset JSON in `tests/smoke_evidence.txt` and `tests/smoke_dataset.json`. **This is an actual script execution, but its HTTP content is simulated, not a live HTTP response.** `.xml.gz` handling is separately covered by tests that execute the decompression path.

### Store metadata and suggested pricing

- **Apify Store category:** `ECOMMERCE` (E-commerce). Suggested output type: Products (URL list).
- **Suggested price:** **$2 per 1,000 collected product URLs** ($0.002 per dataset item), per successful result. No result means no suggested charge.
- `store_metadata.json` contains the classification and proposal. **No billing was configured. No Actor was published or run on Apify.**

# Actor input Schema

## `sitemapUrl` (type: `string`):

A public HTTPS XML sitemap or sitemap index.

## `maxUrls` (type: `integer`):

Stop after this many unique matching URLs (1–100).

## Actor input object example

```json
{
  "sitemapUrl": "https://www.allbirds.com/sitemap.xml",
  "maxUrls": 5
}
```

# 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 = {
    "sitemapUrl": "https://www.allbirds.com/sitemap.xml",
    "maxUrls": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/sitemap-product-url-collector").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 = {
    "sitemapUrl": "https://www.allbirds.com/sitemap.xml",
    "maxUrls": 5,
}

# Run the Actor and wait for it to finish
run = client.actor("eichan/sitemap-product-url-collector").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 '{
  "sitemapUrl": "https://www.allbirds.com/sitemap.xml",
  "maxUrls": 5
}' |
apify call eichan/sitemap-product-url-collector --silent --output-dataset

```

## MCP server setup

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

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/HV5o0kdOmDUxj2uOm/builds/tqgXBKIlD4WW5uls8/openapi.json
