# Table & List Scraper — CSS Selector to JSON (`zd-l2/table-list-scraper`) Actor

Turn any HTML page into clean JSON with CSS selectors. Follows "next page" links automatically, no browser needed — runs in seconds and costs a fraction of a Playwright scraper. Pay only per item scraped.

- **URL**: https://apify.com/zd-l2/table-list-scraper.md
- **Developed by:** [Wei Yihao](https://apify.com/zd-l2) (community)
- **Categories:** Developer tools, Automation
- **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/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

## Table & List Scraper — CSS Selector to JSON

Turn any HTML **table or repeated list** into clean JSON. Point it at a URL, give it a CSS selector, get rows back — with pagination handled for you.

Built for the boring 80% of scraping work: price tables, product listings, directory pages, league tables, "results per page" grids.

### Input

| Field | Type | Default | Notes |
|---|---|---|---|
| `startUrls` | array | `[{"url":"https://books.toscrape.com/"}]` | One or more pages to open |
| `itemSelector` | string | `table tr` | CSS selector for each row/item |
| `fields` | object | auto | `selector` or `selector@attribute`; omit to return every cell as `col_1…col_n` |
| `pagination.nextSelector` | string | `null` | CSS selector of the "next page" link |
| `pagination.maxPages` | integer | `1` | Hard stop |
| `maxItems` | integer | `100` | Hard stop across all pages |

Field syntax: `"td:nth-child(2)"` → text, `"a@href"` → attribute, `"a@title"` → attribute.

### Output

```json
{
  "title": "A Light in the Attic",
  "price": "£51.77",
  "link": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
  "stock": "In stock",
  "_sourceUrl": "https://books.toscrape.com/",
  "_page": 1
}
```

Every record carries `_sourceUrl` and `_page`, so a 2,000-row pull stays traceable.

### One-call example

```bash
curl -X POST "https://api.apify.com/v2/acts/ZD-l2~table-list-scraper/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "startUrls": [{"url": "https://books.toscrape.com/"}],
    "itemSelector": "article.product_pod",
    "fields": {"title": "h3 a@title", "price": ".price_color", "link": "h3 a@href"},
    "pagination": {"nextSelector": "li.next a@href", "maxPages": 3}
  }'
```

Reference run: **40 rows in ~11 s, $0.0004 of compute**.

### Limits

- Static HTML only — no JavaScript rendering. For SPAs use a browser-based Actor.
- One CSS selector per field; no XPath.
- Respect the target site's robots.txt and terms. You are responsible for what you scrape.

### Pricing

Pay per result — charged per scraped item, not per minute. A failed page costs nothing.

# Actor input Schema

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

Pages to start from. Each item may be a plain URL string or {"url": "..."}.

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

CSS selector that matches ONE row or card on the page.

## `fields` (type: `object`):

Map of output field name to {selector, attr, all}. selector is applied INSIDE the row; attr defaults to "text"; all=true returns every match as an array.

## `pagination` (type: `object`):

nextSelector = CSS selector of the "next page" link (empty = single page). maxPages caps pages per start URL.

## `maxItems` (type: `integer`):

Hard cap on pushed rows, protects your budget.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://books.toscrape.com/"
    }
  ],
  "itemSelector": "table tbody tr",
  "fields": {
    "title": {
      "selector": "h3 a",
      "attr": "title"
    },
    "price": {
      "selector": ".price_color",
      "attr": "text"
    },
    "link": {
      "selector": "h3 a",
      "attr": "href"
    }
  },
  "pagination": {
    "nextSelector": "li.next a",
    "maxPages": 3
  },
  "maxItems": 500
}
```

# Actor output Schema

## `items` (type: `string`):

Dataset of scraped rows, one object per item.

# 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/"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("zd-l2/table-list-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/" }] }

# Run the Actor and wait for it to finish
run = client.actor("zd-l2/table-list-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/"
    }
  ]
}' |
apify call zd-l2/table-list-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,zd-l2/table-list-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/CljeUedibBijuUAu9/builds/gH4WP8ucUARKpnXLl/openapi.json
