# Efficient scraping: batches, retries and timeouts | Spider

Concurrency, budgets, caching and return formats that keep a large crawl fast and cheap. The settings that matter at scale, and the ones that do not.

Canonical: https://spider.cloud/docs/core/efficient-scraping/

Ways to cut latency and credits when you scrape thousands of pages.

## Several URLs in one request

Pass a comma-separated list in `url`. Spider fetches them concurrently in one request, which suits paginated lists or any known set of pages that share one configuration. Add [streaming](https://spider.cloud/docs/core/concurrent-streaming/) to read results as they finish.

Multiple URLs

```
params = {
	"url": "https://www.example.com, https://example2.com",
	"limit": 25,
	"return_format": "markdown"
}
```

## Batch mode

When each URL needs its own `limit`, `request` mode or `return_format`, send an array of parameter objects. Each entry runs with its own settings.

Batch mode

```
params = [
    {
        "url": "https://www.example.com",
        "limit": 5,
        "return_format": "markdown"
    },
    {
        "url": "https://www.example2.com/",
        "limit": 10,
        "return_format": "markdown"
    },
    {
        "url": "https://www.example3.com/",
        "limit": 1,
        "return_format": "raw"
    }
]
```

## Retries

Spider retries failed requests on its own through residential proxies. If you retry by hand, stop at 2 attempts and change something each time, such as switching `http` to `browser`. Do not retry a hard failure such as [404](https://spider.cloud/docs/core/error-codes/#404-body) or [401](https://spider.cloud/docs/core/error-codes/#401-body).

Tip

Change one setting per retry.

## Timeouts

`request_timeout` caps how long Spider waits on one page; the default is `120` seconds. Raise it for pages with interactions. `crawl_timeout` caps the whole crawl. Size it to your page limit.

Crawl timeout

```
params = {
    "url": "https://www.example.com",
    "limit": 20,
    "return_format": "markdown",
    "crawl_timeout": {
        "secs": 120,
        "nanos": 0
    }
}
```

### Client timeouts

Your HTTP client can time out too. With Python's `requests` library, pass separate connection and read timeouts.

Client timeout

```
import requests, os

headers = {
    'Authorization': f'Bearer {os.getenv("SPIDER_API_KEY")}',
    'Content-Type': 'application/json',
}

CONNECTION_TIMEOUT = 15
READ_TIMEOUT = 30

params = {
	"url": "https://www.example.com",
	"limit": 25,
	"depth": 3,
	"return_format": "markdown"
}

response = requests.post(
    'https://api.spider.cloud/crawl',
    headers=headers,
    json=params,
	stream=True, # Applies to time between consecutive data chunks in streaming mode
	timeout=(CONNECTION_TIMEOUT, READ_TIMEOUT)
)

print(response.json())
```

Tip

For single-page requests, a client read timeout of `60 secs` with one immediate retry keeps a slow page from holding up the queue. Tune both to your volume and page count.

## Concurrency and streaming

Pages fetch concurrently, up to 10,000 requests per minute. Pair that with [streaming](https://spider.cloud/docs/core/concurrent-streaming/) to read results as they arrive.
