# Crawl

Give it a starting page and get the site's pages back as clean text, as a job.

```text
POST   https://api.millionshort.com/v1/crawl
GET    https://api.millionshort.com/v1/crawl
GET    https://api.millionshort.com/v1/crawl/{id}
DELETE https://api.millionshort.com/v1/crawl/{id}
```

A crawl starts at one page, finds the pages of the site from its sitemap and its links, and returns each one as clean text. It runs in the background: you get a job at once, poll it for pages as they finish, and can be told by [webhook](https://millionshort.com/docs/webhooks) when it ends.

A crawl is an [Extract batch](https://millionshort.com/docs/extract/batch) that finds its own URLs. Every page comes back in the shape of an Extract result, with one more field, `depth`.

## What it is for

- **Bringing a section of a site into a knowledge base.** The docs, the help centre, a blog.
- **Giving an agent a whole small site to read.**
- **Keeping only some kinds of page.** Every page carries [labels](https://millionshort.com/docs/extract/labels): its topic, its kind, and the source that holds pages like it. They are free, and a crawl can keep only the pages with the labels you name.

## How pages are found

- The page you name is always crawled. It is depth 0.
- The site's sitemaps are read when the crawl starts. Their URLs are depth 1.
- Every page that comes back gives its links. A link is one deeper than the page it was on.
- `max_depth` says how far to go, `max_pages` how many pages you pay for at most, and `include` and `exclude` which paths.
- By default a crawl stays on the host you named. It can widen to the site's other hosts, or follow links off the site, only when you ask.

Pages nearest the start come first.

## How pages are obtained

One field, `mode`, decides, as it does for [Extract](https://millionshort.com/docs/extract):

| Mode | What it does |
|---|---|
| `live` | Fetches each page now, as our declared bot. The default |
| `rendered` | Loads each page in a browser, so content built by scripts appears. Paid plans |
| `unblock` | A rendered fetch for sites that refuse automated requests. Growth plan and above |
| `cached` | Returns the copies we already hold. No page is requested from the site |

A `cached` crawl is the one that asks least of a site: the site is asked for its robots.txt and its sitemaps, and for no page at all. When that robots.txt closes the start page to our bot, the crawl ends and nothing is served.

## How we treat the site

We identify ourselves to sites as `MillionShortBot`. robots.txt is honoured for every page we fetch, and there is no option to ignore it. A site gets at most one page a second from all our customers together, and one account at most 30 pages of one site a minute and 2,000 a day. A crawl of one site is slow on purpose: a large one takes hours. A caller cannot send cookies, headers or a delay to a site.

## What it costs

A crawled page costs 1 credit in `cached` and `live`, 2 in `rendered` and 26 in `unblock`. A page that fails is free, except a page a browser mode found missing. The crawl holds the price of `max_pages` when you start it, never costs more than that, and hands back what it did not use. [Pricing and limits](https://millionshort.com/docs/crawl/pricing) has the table.

## In this section

| Part | Page |
|---|---|
| Quickstart | [Start a crawl, poll it, read the pages](https://millionshort.com/docs/crawl/quickstart) |
| Parameters | [Every request field, the job, and the results](https://millionshort.com/docs/crawl/parameters) |
| Guides | [One section of a site, paging, webhooks, stored copies, labels](https://millionshort.com/docs/crawl/guides) |
| Pricing and limits | [What a page costs in each mode, and the limits](https://millionshort.com/docs/crawl/pricing) |
| Errors | [Request errors, why a crawl stopped, per-page errors](https://millionshort.com/docs/crawl/errors) |

## With the other endpoints

[Map](https://millionshort.com/docs/map) lists a site's URLs without reading them, in one call. [Extract](https://millionshort.com/docs/extract) reads URLs you already have. [Monitor](https://millionshort.com/docs/monitor) watches one page for changes.
