# No-Code CSS Selector Scraper - Fast Cheerio HTTP Crawler (`sonic_scraper/cheerio-web-scraper`) Actor

No-code web scraper: map field names to CSS selectors, crawl links, and get clean JSON/CSV. Page metadata and JSON-LD extracted automatically. Optional JavaScript page function, proxies, robots.txt. Fast HTTP, no browser.

- **URL**: https://apify.com/sonic_scraper/cheerio-web-scraper.md
- **Developed by:** [Sonic Scraper](https://apify.com/sonic_scraper) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.70 / 1,000 web page results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## No-Code CSS Selector Scraper - Fast Cheerio HTTP Crawler

Scrape static websites **without writing code**: map field names to CSS selectors, point the Actor at your start URLs, and get clean JSON, CSV, or Excel. Page title, meta description, canonical URL, H1s, Open Graph image, and JSON-LD structured data are extracted automatically. Need full control? Add an optional JavaScript page function.

### What can this CSS selector scraper do?

- **No-code extraction rules** - each rule has a `name`, a CSS `selector`, a `type` (`text`, `html`, or `attribute`), and an optional `multiple` flag for lists.
- **Automatic page metadata** - title, description, canonical URL, language, H1 headings, and Open Graph image.
- **Automatic JSON-LD** - parses `application/ld+json` structured data (products, articles, organizations, events...).
- **Recursive crawling** - follow links matched by a `linkSelector`, filtered by include `globs` and `excludes`, with depth and page limits.
- **JavaScript page function** - return any JSON from each page when CSS rules are not enough; `customData` is available in context.
- **Production controls** - concurrency, retries, timeouts, custom headers, Apify Proxy or your own proxies, and robots.txt compliance (on by default).
- **Clean output** - empty fields can be removed automatically.

### What data can I extract?

| Field | Description |
|---|---|
| `url` | The page URL |
| *your rule names* | Values from your CSS rules (string, or array when `multiple` is on) |
| `title`, `description`, `canonicalUrl`, `language`, `h1`, `image` (Open Graph) | Page metadata (when `includePageMetadata` is on) |
| `jsonLd` | Parsed JSON-LD objects (when `includeJsonLd` is on) |

When a page function is supplied, its return value replaces the CSS-rule output.

### How much does it cost?

Pay-per-event: **$0.001 per result** ($1.00 per 1,000 records) plus a tiny Actor-start fee. `maxResultsPerCrawl` caps the number of billable records. Check the Pricing tab for current rates.

### How to scrape a website with CSS selectors

1. Add start URLs.
2. Add extraction rules, for example `{"name": "price", "selector": ".price_color", "type": "text"}`.
3. Optional: set `linkSelector` (e.g. `a[href]`) and `globs` to crawl more pages.
4. Click **Start** and export the dataset.

### Input example

```json
{
  "startUrls": [{ "url": "https://books.toscrape.com/" }],
  "extractionRules": [
    { "name": "titles", "selector": "article.product_pod h3 a", "type": "attribute", "attribute": "title", "multiple": true },
    { "name": "prices", "selector": "article.product_pod .price_color", "type": "text", "multiple": true }
  ],
  "linkSelector": "li.next a",
  "maxCrawlingDepth": 3,
  "maxPagesPerCrawl": 50
}
```

### Output example

```json
{
  "url": "https://books.toscrape.com/",
  "titles": ["A Light in the Attic", "Tipping the Velvet"],
  "prices": ["£51.77", "£53.74"],
  "title": "All products | Books to Scrape - Sandbox"
}
```

### Use cases

- Product catalogs and prices from static ecommerce sites
- Directory and listing pages
- SEO metadata and JSON-LD collection across many URLs
- Quick one-off data pulls without writing a crawler

### API example

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("sonic_scraper/cheerio-web-scraper").call(run_input={
    "startUrls": [{"url": "https://books.toscrape.com/"}],
    "extractionRules": [{"name": "heading", "selector": "h1", "type": "text"}],
})
print(list(client.dataset(run["defaultDatasetId"]).iterate_items())[:3])
```

### Use with AI agents (MCP)

Connect the Apify MCP server at `https://mcp.apify.com?tools=sonic_scraper/cheerio-web-scraper` in Claude Desktop, Cursor, VS Code or any MCP client, and your AI assistant can call this actor as a tool. Example prompt: *"Scrape the product names and prices from these 20 category URLs with these CSS selectors and return a table."*

### FAQ

**Does it run JavaScript on the page?** No. It fetches raw HTML over HTTP, which makes it fast and cheap but unsuitable for sites that render content in the browser.

**How is it different from Apify's Cheerio Scraper?** Apify's Cheerio Scraper is code-first (you write a page function). This Actor adds no-code CSS rules plus automatic metadata and JSON-LD, while still accepting a page function.

**Does it respect robots.txt?** Yes, by default (`respectRobotsTxtFile`).

### Related Actors

- [Website Screenshot API](https://apify.com/sonic_scraper/website-screenshot-api) - full-page, mobile, element and PDF screenshots with cookie banners hidden.
- [Website to Markdown Crawler](https://apify.com/sonic_scraper/ai-rag-web-crawler) - full-page Markdown for LLMs.
- [Technical SEO Audit Crawler](https://apify.com/sonic_scraper/technical-seo-audit-crawler) - SEO issues per page.

# Changelog

This Actor's version history is a separate document: https://apify.com/sonic_scraper/cheerio-web-scraper/changelog.md

# Actor input Schema

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

Pages where the crawl begins. Static HTML, JSON, XML, and text responses are supported.

## `extractionRules` (type: `array`):

No-code extraction rules. Each rule needs a name and CSS selector. Use type text, html, or attribute; set multiple to return every match.

## `pageFunction` (type: `string`):

Optional async JavaScript function executed for every page. When supplied, its return value replaces CSS-rule output. Context includes $, request, response, body, json, crawler, Actor, log, and customData.

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

CSS selector for links to follow. Leave empty to scrape only Start URLs.

## `globs` (type: `array`):

Only follow links matching these patterns. Empty means all links selected above.

## `excludes` (type: `array`):

Never follow links matching these patterns.

## `sameDomainOnly` (type: `boolean`):

Prevent discovered links from leaving the domains supplied in Start URLs.

## `maxCrawlingDepth` (type: `integer`):

How many link levels beyond each Start URL can be crawled.

## `maxPagesPerCrawl` (type: `integer`):

Stop after processing this many HTTP pages.

## `maxResultsPerCrawl` (type: `integer`):

Stop writing results after this many dataset items.

## `includePageMetadata` (type: `boolean`):

Include title, description, canonical URL, language, H1 headings, and Open Graph image.

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

Parse valid structured data from application/ld+json script elements.

## `removeEmptyFields` (type: `boolean`):

Omit null, empty-string, and empty-array fields from automatic results.

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

Use Apify Proxy or your own proxy URLs for protected websites.

## `additionalHeaders` (type: `object`):

Headers sent with every request, such as Authorization or Accept-Language.

## `maxConcurrency` (type: `integer`):

Maximum number of pages fetched at the same time.

## `maxRequestRetries` (type: `integer`):

Retry failed HTTP requests this many times.

## `requestTimeoutSecs` (type: `integer`):

Maximum time allowed for a page request.

## `respectRobotsTxtFile` (type: `boolean`):

Check and honor each site's robots.txt rules.

## `customData` (type: `object`):

Arbitrary values available as context.customData in the page function.

## `debugLog` (type: `boolean`):

Enable verbose logs for troubleshooting.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://books.toscrape.com/"
    }
  ],
  "extractionRules": [
    {
      "name": "pageTitle",
      "selector": "h1",
      "type": "text"
    },
    {
      "name": "products",
      "selector": ".product_pod h3 a",
      "type": "attribute",
      "attribute": "title",
      "multiple": true
    }
  ],
  "pageFunction": "",
  "linkSelector": "a[href]",
  "globs": [
    {
      "glob": "https://books.toscrape.com/catalogue/**"
    }
  ],
  "excludes": [
    {
      "glob": "**/*.{jpg,jpeg,png,gif,svg,pdf,zip}"
    }
  ],
  "sameDomainOnly": true,
  "maxCrawlingDepth": 1,
  "maxPagesPerCrawl": 100,
  "maxResultsPerCrawl": 100,
  "includePageMetadata": true,
  "includeJsonLd": true,
  "removeEmptyFields": true,
  "proxyConfiguration": {
    "useApifyProxy": false
  },
  "additionalHeaders": {},
  "maxConcurrency": 20,
  "maxRequestRetries": 3,
  "requestTimeoutSecs": 45,
  "respectRobotsTxtFile": true,
  "customData": {},
  "debugLog": false
}
```

# Actor output Schema

## `dataset` (type: `string`):

Structured records returned by CSS rules or the page function.

## `output` (type: `string`):

Result count and completion time.

# 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/"
        }
    ],
    "extractionRules": [
        {
            "name": "pageTitle",
            "selector": "h1",
            "type": "text"
        },
        {
            "name": "products",
            "selector": ".product_pod h3 a",
            "type": "attribute",
            "attribute": "title",
            "multiple": true
        }
    ],
    "linkSelector": "a[href]",
    "globs": [
        {
            "glob": "https://books.toscrape.com/catalogue/**"
        }
    ],
    "excludes": [
        {
            "glob": "**/*.{jpg,jpeg,png,gif,svg,pdf,zip}"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("sonic_scraper/cheerio-web-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/" }],
    "extractionRules": [
        {
            "name": "pageTitle",
            "selector": "h1",
            "type": "text",
        },
        {
            "name": "products",
            "selector": ".product_pod h3 a",
            "type": "attribute",
            "attribute": "title",
            "multiple": True,
        },
    ],
    "linkSelector": "a[href]",
    "globs": [{ "glob": "https://books.toscrape.com/catalogue/**" }],
    "excludes": [{ "glob": "**/*.{jpg,jpeg,png,gif,svg,pdf,zip}" }],
}

# Run the Actor and wait for it to finish
run = client.actor("sonic_scraper/cheerio-web-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/"
    }
  ],
  "extractionRules": [
    {
      "name": "pageTitle",
      "selector": "h1",
      "type": "text"
    },
    {
      "name": "products",
      "selector": ".product_pod h3 a",
      "type": "attribute",
      "attribute": "title",
      "multiple": true
    }
  ],
  "linkSelector": "a[href]",
  "globs": [
    {
      "glob": "https://books.toscrape.com/catalogue/**"
    }
  ],
  "excludes": [
    {
      "glob": "**/*.{jpg,jpeg,png,gif,svg,pdf,zip}"
    }
  ]
}' |
apify call sonic_scraper/cheerio-web-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,sonic_scraper/cheerio-web-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/iFgdsVkeB8h8vgVh0/builds/KFhCAa5uH6oyf9mIk/openapi.json
