# Spider Scrape API

> POST a URL and Spider returns the page as markdown, HTML or text, with the fields you mapped to selectors.

Generated from the data behind https://spider.cloud/api/scrape/, so the figures here match the page.

## Endpoint

`POST https://api.spider.cloud/scrape`, with your API key as a bearer token. Pay as you go, from $1 per GB, with no subscription. The response is an array with one object per URL.

## One page, requested three ways

Recorded on 2026-11-17 from a laptop, against books.toscrape.com, a public sandbox site. This is the request as sent for markdown.

```json
{
  "url": "https://books.toscrape.com/catalogue/its-only-the-himalayas_981/index.html",
  "return_format": "markdown",
  "css_extraction_map": {
    "/": [
      {
        "name": "title",
        "selectors": [
          ".product_main h1"
        ]
      },
      {
        "name": "price",
        "selectors": [
          ".product_main .price_color"
        ]
      },
      {
        "name": "stock",
        "selectors": [
          ".product_main .availability"
        ]
      }
    ]
  }
}
```

Each selector in the map came back as a named field under `css_extracted`.

| Field | Selector sent | Value returned |
|---|---|---|
| `title` | `.product_main h1` | It's Only the Himalayas |
| `price` | `.product_main .price_color` | £45.17 |
| `stock` | `.product_main .availability` | In stock (19 available) |

The same URL and map went out 3 times, changing only `return_format`. Every response was HTTP 200 with the same 3 fields. What changed is `content`:

| `return_format` | `content` is | Characters | Lines | Wall time | Response size |
|---|---|---|---|---|---|
| `raw` | HTML as fetched | 19,320 | 820 | 1.486 s | 22,817 bytes |
| `markdown` | markdown | 3,988 | 75 | 1.217 s | 6,279 bytes |
| `text` | plain text | 2,256 | 10 | 1.074 s | 4,520 bytes |

Wall time is the whole call as the laptop measured it. Response size is the whole JSON body.

`content` for `raw`, lines 132 to 175 of 820, no blank lines:

```html
        <div id="product_gallery" class="carousel">
            <div class="thumbnail">
                <div class="carousel-inner">
                    <div class="item active">
                            <img src="../../media/cache/6d/41/6d418a73cc7d4ecfd75ca11d854041db.jpg" alt="It&#39;s Only the Himalayas" />
                    </div>
                </div>
            </div>
        </div>
        </div>
        <div class="col-sm-6 product_main">
            <h1>It&#39;s Only the Himalayas</h1>
        <p class="price_color">£45.17</p>
<p class="instock availability">
    <i class="icon-ok"></i>
        In stock (19 available)
</p>
```

`content` for `markdown`, lines 1 to 11 of 75:

```markdown
It's Only the Himalayas | Books to Scrape - Sandbox
* [Home](../../index.html)
* [Books](../category/books_1/index.html)
* [Travel](../category/books/travel_2/index.html)
* It's Only the Himalayas
![It&#39;s Only the Himalayas](../../media/cache/6d/41/6d418a73cc7d4ecfd75ca11d854041db.jpg)
# It's Only the Himalayas
£45.17
**
In stock (19 available)
**
```

`content` for `text`, all 10 lines, line 4 cut short:

```text
It&#39;s Only the Himalayas | Books to Scrape - Sandbox
Home Books Travel It&#39;s Only the Himalayas It&#39;s Only the Himalayas £45.17 In stock (19 available)
&nbsp;
Warning! This is a demo website for web scraping purposes. Prices and ratings here were randomly assigned and have no real meaning. Product Description ...
Add to basket Mesaerion: The Best Science ... £37.59 In stock
Add to basket Olio £23.88 In stock
Add to basket Our Band Could Be ... £57.25 In stock
Add to basket Rip it Up and ... £35.02 In stock
Add to basket Scott Pilgrim&#39;s Precious Little ... £52.29 In stock
Add to basket
```

The `costs` object on each response, in US dollars. Each column is the receipt for that one request, and a page that transfers more costs more.

| Key | `raw` | `markdown` | `text` |
|---|---|---|---|
| `compute_cost` | 0.00000247 | 0.00000144 | 0.00000170 |
| `bytes_transferred_cost` | 0.00000080 | 0.00000080 | 0.00000080 |
| `file_cost` | 0.00005199 | 0.00005199 | 0.00005199 |
| `transform_cost` | 0.00000000 | 0.00001790 | 0.00001790 |
| `total_cost` | 0.00005525 | 0.00007213 | 0.00007239 |

## The same request in code

```bash
curl https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://books.toscrape.com/catalogue/its-only-the-himalayas_981/index.html",
    "return_format": "markdown",
    "css_extraction_map": {
      "/": [
        { "name": "title", "selectors": [".product_main h1"] },
        { "name": "price", "selectors": [".product_main .price_color"] },
        { "name": "stock", "selectors": [".product_main .availability"] }
      ]
    }
  }'
```

```python
from spider import Spider

client = Spider()

url = (
    "https://books.toscrape.com/catalogue/"
    "its-only-the-himalayas_981/index.html"
)
fields = {
    "title": ".product_main h1",
    "price": ".product_main .price_color",
    "stock": ".product_main .availability",
}
selector_map = [
    {"name": name, "selectors": [css]}
    for name, css in fields.items()
]

pages = client.scrape_url(
    url,
    params={
        "return_format": "markdown",
        "css_extraction_map": {
            "/": selector_map,
        },
    },
)

print(pages[0]["css_extracted"])
```

```javascript
import {
  Spider,
} from "@spider-cloud/spider-client";

const client = new Spider();

const url =
  "https://books.toscrape.com/catalogue/" +
  "its-only-the-himalayas_981/index.html";
const fields = {
  title: ".product_main h1",
  price: ".product_main .price_color",
  stock: ".product_main .availability",
};

const pages = await client.scrapeUrl(url, {
  return_format: "markdown",
  css_extraction_map: {
    "/": Object.entries(fields).map(
      ([name, css]) => ({
        name,
        selectors: [css],
      }),
    ),
  },
});

console.log(pages[0].css_extracted);
```

## The selector map

- `"/"`: A map key is a URL path, and this one runs its fields on every page.
- `"/any/path"`: Any other key runs only on the page whose path is exactly that key, so a prefix matches nothing.
- `selectors`: A field takes CSS or XPath and more than one selector, so one map can outlast a template change.

## Request modes

The `request` parameter sets how Spider fetches a page.

| `request` | Pick it when | What runs | JavaScript |
|---|---|---|---|
| `smart`, the default | Most pages, and any batch you are not sure about. | Spider inspects each page and picks HTTP or Chrome per URL, so you pay for rendering only on the pages that need it. | When detected |
| `http` | You know the page renders on the server. | A plain fetch with no browser, for docs, feeds and any page that already works with curl. | No |
| `browser` | The request sends scripts, waits or scrolling. | Chrome renders every page. automation_scripts, evaluate_on_new_document, wait_for and scroll run only here, and a smart request can finish on HTTP and skip them. | Always |

## What you send and what comes back

A row with no request field is always in the response.

| Request field | Response field | What it does |
|---|---|---|
| `return_format` | `content` | The page as markdown, raw HTML, text or bytes. |
| `css_extraction_map` | `css_extracted` | Named fields from your selector map. |
| `return_json_data` | `json_data` | JSON-LD, product schema and the state objects a framework ships inside the page. |
| `readability` | `content` | The main body with navigation, sidebars and ads removed. |
| `evaluate_on_new_document` |  | Your script runs before extraction, on a browser request. |
| `url` |  | Comma-separate URLs or send an array of objects, and the whole list comes back as one array. |
| `metadata` | `metadata` | Title, description and keywords. |
| `return_page_links` | `links` | Every link found on the page. |
| `return_headers` | `headers` | The response headers. |
| `return_cookies` | `cookies` | The cookies the page set. |
|  | `url` | The final URL after redirects. |
|  | `status` | The HTTP status of the fetch. |
|  | `costs` | What this request cost, with compute and transfer split out. |
|  | `error` | Set per page, so one bad URL does not fail the batch. |

## Scrape or Crawl

Scrape fetches the URLs you name and never follows a link, and [Crawl](https://spider.cloud/api/crawl/) finds those URLs for you with the same parameters and response shape.

## Links

- Page: https://spider.cloud/api/scrape/
- Docs: https://spider.cloud/docs/api/scrape/
- Try one page with no key: https://spider.cloud/web-scraper/
- Rates: https://spider.cloud/pricing/
