# CSS Selector Scraper – no-code, XPath, pagination – $0.8/1k (`henrycrawl/css-selector-scraper`) Actor

Scrape any public website without code: CSS/XPath fields, repeated items, next-page pagination, 1-level detail links, JSON-LD & meta tags. Fast HTTP, no browser. Works with AI agents via Apify MCP. Pay per row; blocked rows are free.

- **URL**: https://apify.com/henrycrawl/css-selector-scraper.md
- **Developed by:** [Henry Crawl](https://apify.com/henrycrawl) (community)
- **Categories:** Developer tools, Automation, AI
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.80 / 1,000 scraped rows

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

## CSS Selector Scraper – no-code web scraper (CSS / XPath)

Turn any public web page into clean JSON rows **without writing code**: list the fields you want as CSS or XPath selectors and the actor does the rest – repeated items, next-page pagination, one level of detail pages, JSON-LD and meta tags. It uses fast plain HTTP (no browser), so runs finish in seconds and cost very little.

Great for AI agents: an agent can look at a page, write the selectors and call this actor through Apify MCP.

### What it does

- **Item mode** – set `itemSelector` (e.g. `article.product_pod`): every match becomes one row, field selectors run inside it.
- **Page mode** – leave `itemSelector` empty: one row per page (optionally with meta tags and JSON-LD).
- **Pagination** – `nextPageSelector` (e.g. `li.next a`, `a[rel=next]`) is followed up to `maxPages`.
- **Detail pages** – `linkSelector` (e.g. `article h3 a`) opens each linked page (1 level deep) and extracts the fields there.
- **CSS or XPath** – selectors starting with `/`, `./`, `(` or `xpath:` are XPath (e.g. `//th[text()='UPC']/following-sibling::td`).
- **Blocked pages** (403 / 429 / captcha / bot-check) come back as free `BLOCKED` rows. The actor does not try to bypass protections; JavaScript-only sites need a browser actor.

### Input

| Field | Description |
|---|---|
| `startUrls` | Pages to start from, `[{"url": "https://..."}]` |
| `itemSelector` | Optional CSS/XPath for repeated items |
| `fields` | List of `{"name", "selector", "attr", "multiple"}`. `attr`: `text` (default), `html`, `outerHtml`, `href`/`src` (made absolute) or any attribute. `multiple: true` returns a list |
| `nextPageSelector`, `maxPages` | Pagination link and how many pages per start URL (default 10) |
| `linkSelector`, `maxLinksPerPage` | Detail links to open, 1 level deep |
| `includeMeta` | Page mode: title, description, canonical, language, H1, Open Graph / Twitter tags (on by default when no fields) |
| `includeJsonLd` | Page mode: all schema.org JSON-LD blocks |
| `useApifyProxy` | Use Apify datacenter proxy (off by default) |
| `maxResults` | Max charged rows for the run |

#### Example input

```json
{
  "startUrls": [{"url": "https://books.toscrape.com/"}],
  "itemSelector": "article.product_pod",
  "fields": [
    {"name": "title", "selector": "h3 a", "attr": "title"},
    {"name": "price", "selector": ".price_color"},
    {"name": "productUrl", "selector": "h3 a", "attr": "href"},
    {"name": "rating", "selector": "p.star-rating", "attr": "class"}
  ],
  "nextPageSelector": "li.next a",
  "maxPages": 3,
  "maxResults": 60
}
```

Detail pages with XPath:

```json
{
  "startUrls": [{"url": "https://books.toscrape.com/catalogue/category/books/travel_2/index.html"}],
  "linkSelector": "article.product_pod h3 a",
  "fields": [
    {"name": "title", "selector": "h1"},
    {"name": "price", "selector": ".product_main .price_color"},
    {"name": "upc", "selector": "//th[text()='UPC']/following-sibling::td"},
    {"name": "breadcrumbs", "selector": ".breadcrumb li a", "multiple": true}
  ]
}
```

### Output

| Field | Description |
|---|---|
| `pageUrl` / `url` | Listing page (item mode) or page URL (page / detail mode) |
| `pageNumber`, `itemIndex` | Position of the row |
| *your fields* | One key per field name |
| `sourcePageUrl` | Listing page a detail page came from |
| `meta`, `jsonLd` | When enabled (page mode) |
| `type`, `status`, `scrapedAt` | `result` / `OK`, or `error` with a code: `BLOCKED`, `HTTP_ERROR`, `NO_ITEMS`, `NO_LINKS`, `BAD_FIELD`, `BAD_SELECTOR`, `UNSUPPORTED_CONTENT`, `FETCH_FAILED` |

Real rows from a test run:

```json
{"pageUrl": "https://books.toscrape.com/", "pageNumber": 1, "itemIndex": 0, "title": "A Light in the Attic", "price": "£51.77", "productUrl": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html", "image": "https://books.toscrape.com/media/cache/2c/da/2cdad67c44b002e7ead0cc35693c0e8b.jpg", "rating": "star-rating Three", "availability": "In stock", "type": "result", "status": "OK", "scrapedAt": "2026-11-22T13:59:00.769013+00:00"}
{"url": "https://books.toscrape.com/catalogue/its-only-the-himalayas_981/index.html", "pageNumber": 1, "title": "It's Only the Himalayas", "price": "£45.17", "upc": "a22124811bfa8350", "breadcrumbs": ["Home", "Books", "Travel"], "sourcePageUrl": "https://books.toscrape.com/catalogue/category/books/travel_2/index.html", "type": "result", "status": "OK"}
{"status": "BLOCKED", "error": "The site blocked this request (HTTP 403). Not bypassed; not charged.", "url": "https://httpbin.org/status/403", "httpStatus": 403, "type": "error"}
```

### Pricing

Pay per event: **$0.80 per 1,000 rows** ($0.0008 per row). Error and blocked rows are free. `maxResults` and your run spending limit are always respected.

### Use with AI agents (MCP)

Add this actor as a tool to Claude, Cursor or any MCP client:

`https://mcp.apify.com/?tools=henrycrawl/css-selector-scraper`

The agent passes `startUrls` plus the selectors it wants and gets structured JSON back – a quick way to give an agent "read this table / list from any site" skills.

### Limits

- No JavaScript rendering: content loaded by client-side JS is not visible (use the page's JSON API or a browser actor).
- Only public pages; no login, no captcha solving.

# Actor input Schema

## `startUrls` (type: `array`):

Pages to start from (listing pages, search results or single pages). Plain URLs or {"url": ...} objects.

## `itemSelector` (type: `string`):

CSS or XPath selector for repeated items (e.g. 'article.product_pod', 'div.quote', '//li\[@class="result"]'). Each match becomes one row and field selectors run inside it. Leave empty for one row per page.

## `fields` (type: `array`):

List of fields to extract: {"name": "price", "selector": ".price", "attr": "text", "multiple": false}. selector = CSS or XPath (starts with / or ./ or 'xpath:'). attr = text (default), html, outerHtml, href, src (made absolute), or any attribute name. multiple = true returns a list of all matches. A simple {"name": "selector"} object also works.

## `nextPageSelector` (type: `string`):

CSS or XPath selector of the 'next page' link (e.g. 'li.next a', 'a\[rel=next]'). Its href is followed until maxPages. Leave empty for no pagination.

## `maxPages` (type: `integer`):

How many listing pages to follow with the next-page selector, per start URL.

## `linkSelector` (type: `string`):

Optional CSS or XPath selector of links to open (e.g. 'article h3 a'). When set, start/listing pages only provide links and pagination; the fields are extracted from each linked detail page.

## `maxLinksPerPage` (type: `integer`):

Cap on how many detail links are opened from each listing page.

## `includeMeta` (type: `boolean`):

Page mode only (no item selector): add title, meta description, canonical, language, H1 and Open Graph / Twitter tags. On by default when no fields are given.

## `includeJsonLd` (type: `boolean`):

Page mode only: add every schema.org JSON-LD block found on the page (products, articles, events, recipes...).

## `useApifyProxy` (type: `boolean`):

Route requests through Apify datacenter proxy. Blocked pages (403 / captcha / bot-check) are returned as free BLOCKED rows; the actor does not try to bypass protections.

## `maxResults` (type: `integer`):

Maximum number of rows for the whole run (you are only charged for delivered rows; error / blocked rows are free).

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://books.toscrape.com/"
    }
  ],
  "itemSelector": "article.product_pod",
  "fields": [
    {
      "name": "title",
      "selector": "h3 a",
      "attr": "title"
    },
    {
      "name": "price",
      "selector": ".price_color"
    },
    {
      "name": "productUrl",
      "selector": "h3 a",
      "attr": "href"
    },
    {
      "name": "image",
      "selector": "img",
      "attr": "src"
    },
    {
      "name": "rating",
      "selector": "p.star-rating",
      "attr": "class"
    },
    {
      "name": "availability",
      "selector": ".availability"
    }
  ],
  "maxPages": 10,
  "maxLinksPerPage": 1000,
  "includeJsonLd": false,
  "useApifyProxy": false,
  "maxResults": 20
}
```

# Actor output Schema

## `results` (type: `string`):

One row per result, plus free error rows (type = error).

## `summary` (type: `string`):

Counts for this run (SUMMARY record).

# 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 = {
    "startUrls": [
        {
            "url": "https://books.toscrape.com/"
        }
    ],
    "itemSelector": "article.product_pod",
    "fields": [
        {
            "name": "title",
            "selector": "h3 a",
            "attr": "title"
        },
        {
            "name": "price",
            "selector": ".price_color"
        },
        {
            "name": "productUrl",
            "selector": "h3 a",
            "attr": "href"
        },
        {
            "name": "image",
            "selector": "img",
            "attr": "src"
        },
        {
            "name": "rating",
            "selector": "p.star-rating",
            "attr": "class"
        },
        {
            "name": "availability",
            "selector": ".availability"
        }
    ],
    "maxResults": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("henrycrawl/css-selector-scraper").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 = {
    "startUrls": [{ "url": "https://books.toscrape.com/" }],
    "itemSelector": "article.product_pod",
    "fields": [
        {
            "name": "title",
            "selector": "h3 a",
            "attr": "title",
        },
        {
            "name": "price",
            "selector": ".price_color",
        },
        {
            "name": "productUrl",
            "selector": "h3 a",
            "attr": "href",
        },
        {
            "name": "image",
            "selector": "img",
            "attr": "src",
        },
        {
            "name": "rating",
            "selector": "p.star-rating",
            "attr": "class",
        },
        {
            "name": "availability",
            "selector": ".availability",
        },
    ],
    "maxResults": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("henrycrawl/css-selector-scraper").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 '{
  "startUrls": [
    {
      "url": "https://books.toscrape.com/"
    }
  ],
  "itemSelector": "article.product_pod",
  "fields": [
    {
      "name": "title",
      "selector": "h3 a",
      "attr": "title"
    },
    {
      "name": "price",
      "selector": ".price_color"
    },
    {
      "name": "productUrl",
      "selector": "h3 a",
      "attr": "href"
    },
    {
      "name": "image",
      "selector": "img",
      "attr": "src"
    },
    {
      "name": "rating",
      "selector": "p.star-rating",
      "attr": "class"
    },
    {
      "name": "availability",
      "selector": ".availability"
    }
  ],
  "maxResults": 20
}' |
apify call henrycrawl/css-selector-scraper --silent --output-dataset

```

## MCP server setup

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

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/igH7yim3WWo1CcuNA/builds/KcM80dARETJVZaIoT/openapi.json
