# How to scrape a paginated site and know when to stop | Spider

Follow a listing from its first page to its last, and stop on the right signal: no next link, the page limit you set, or a page with no items.

Canonical: https://spider.cloud/learn/pagination/

To scrape a paginated site, fetch the first listing page, take its items and its link to the next page, then fetch that link and repeat. Stop when a page has no next link, when you reach the page limit you set, or when a page comes back with no items, whichever comes first.

Most of the work is in the stopping. A loop that follows Next links is short. A loop that knows the difference between the end of the list, the end of its own budget and an empty page that still says 200 OK takes more thought. The runs below show each case.

## What a paginated list is

A site splits a long list into pages when it is too long to send at once: products in a category, posts in an archive, results for a search. Each page shows a slice and links to the slice after it. Google's guidance for site owners says: "To make sure search engines understand the relationship between pages of paginated content, include links from each page to the following page". A site that follows that advice has already built the path your [web scraper](/web-scraping/) needs.

The same document says how those pages should be addressed: "URLs in a paginated sequence are treated as separate pages by Google." For a scraper that means each page has its own address, and you can keep a list of the ones you have fetched.

## How a page points to the next one

This clip finds the next link on a practice catalogue, walks it to the end, and shows the three stops and the guards every walk needs. The same steps follow it in text.

How to walk a paginated list. 1 min 9 s, no sound. The words are on screen, and the captions button shows them at your own text size.

Read the transcript

How to walk a paginated list. Follow the next link, and know which of three stops ended the walk.

Find how the first page points to the next one. Find the next link: GET /page/1/. pager: A Next link or arrow. rel: rel="next". header: A Link header. ?page=2: No end signal.

The walk follows Next until a page has none. Page 10 is the end of the list. The walk starts at /page/1/ and follows the next link on each page. It fetches /page/1/ to /page/10/, one page at a time. /page/10/ has no next link, so the list has ended and the walk stops. 10 pages fetched. 30 the limit you set.

A limit of 4 stops the walk, but page 4 still links on. Mark that run incomplete. The walk starts at /page/1/ and follows the next link on each page. It fetches /page/1/ to /page/4/, one page at a time. The limit is 4, so the walk stops there, and /page/4/ still links to /page/5/. The run is incomplete. 4 pages fetched. 4 the limit you set. /page/5/ next link, not followed.

A loop that counts past the last page gets 200 and no items. Stop there. The walk starts at /page/11/ and adds one to the page number each time. /page/11/ answers 200 with no items on it, so the walk stops. 1 page fetched. 0 items on /page/11/.

A next link can lead back. Normalize each URL before you compare. Guards for every walk: a set of fetched URLs. seen: Stop on a repeat. #: Ignore the fragment. pace: One page, then a pause.

Read the full page. The page is at spider.cloud/learn/pagination.

Look at the first listing page before you write any code, and find which of these it uses.

1. A link in a pager, usually labelled Next or with an arrow. The run below follows this kind.
2. A `rel="next"` attribute on a `link` or `a` element. The HTML Standard defines that keyword as one that "Indicates that the current document is a part of a series, and that the next document in the series is the referenced document." Google's page notes that it stopped reading these tags, and adds "although these links may still be used by other search engines", so a site may still carry them.
3. A `Link` header in the HTTP response. RFC 8288 defines a model for links between resources and, in its own words, "It also defines the serialisation of such links in HTTP headers with the Link header field." An API that pages its results can send `rel="next"` there instead of in the body, so check the headers as well as the page.

Some lists have no link at all, only a counter in the URL such as `?page=2`. You can walk that by adding one each time, but then nothing on the page tells you where the list ends. The third stop condition below exists for that case.

## One practice catalogue, page by page

[Quotes to Scrape](https://quotes.toscrape.com/) is a site built for scraping practice. Its quotes are split over numbered listing pages, each with a pager at the bottom. The crawl below starts on page 1, stays on the listing pages and keeps only the pager block of each one, so the stop signal is the whole output. Have your key in `SPIDER_API_KEY` before you run it.

```bash
curl -s https://api.spider.cloud/crawl \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://quotes.toscrape.com/page/1/", "request": "http", "return_format": "markdown", "root_selector": "ul.pager", "whitelist": ["/page/"], "limit": 30, "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)", "delay": 1000}'
```

The `whitelist` keeps the crawl on paths that contain `/page/`. The `root_selector` cuts each page down to the element with the class `pager`. The `limit` caps the walk at 30 pages, far more than this list needs. The `delay` waits 1000 milliseconds between pages, and `user_agent` tells the site who is asking.

Our run of it started at 17:29:23 UTC on 2026-11-20. It returned 10 pages in 15.5 seconds, every one with status 200. These are the first two and the last two, with the url and content of each, values unchanged.

```text
https://quotes.toscrape.com/page/1/   200
* [Next](https://quotes.toscrape.com/page/2/)

https://quotes.toscrape.com/page/2/   200
* [Previous](https://quotes.toscrape.com/page/1/)
* [Next](https://quotes.toscrape.com/page/3/)

...pages 3 to 8, each with a Previous and a Next link...

https://quotes.toscrape.com/page/9/   200
* [Previous](https://quotes.toscrape.com/page/8/)
* [Next](https://quotes.toscrape.com/page/10/)

https://quotes.toscrape.com/page/10/  200
* [Previous](https://quotes.toscrape.com/page/9/)
```

Half a minute earlier, at 17:28:55 UTC, we sent the same body without `root_selector`. It came back with the same ten URLs and the full text of each page, quotes, authors and tag links included. The tag and author pages were not crawled, because the whitelist kept the walk on the listing pages.

## The stop conditions, one run each

### 1. The last page has no next link

Page 10 has a Previous link and nothing else. That is the real end of the list, and it is the condition to trust first. The crawl asked for up to 30 pages and returned 10, so the limit did not stop it. The list ran out.

In your own loop the check is a single test. If the pager on this page has no next link, you are done. Store the page you ended on, so the next run can tell whether the list grew.

### 2. The page limit you set

The second run used the same body with `"limit": 4`. It returned four pages at 17:29:47 UTC, and the last of them still pointed onward.

```text
https://quotes.toscrape.com/page/4/   200
* [Previous](https://quotes.toscrape.com/page/3/)
* [Next](https://quotes.toscrape.com/page/5/)
```

This run stopped because it was told to, not because the list ended. Keep the two apart in your results. A walk that ended on a page with a next link is incomplete, and whatever counts or totals you build from it should say so. Set a limit on every walk anyway. A list that never ends, through a bug on the site or a pager that links back to itself, will otherwise run until your budget does.

### 3. A page that comes back with nothing on it

The third request skipped the pager and asked for the page after the last one, the way a loop that counts `?page=n` would. This is a `/scrape` call with the body `{"url": "https://quotes.toscrape.com/page/11/", "request": "http", "return_format": "markdown", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)"}`, sent at 17:29:56 UTC.

```text
https://quotes.toscrape.com/page/11/  200
Quotes to Scrape
#
[Quotes to Scrape](https://quotes.toscrape.com/)
[Login](https://quotes.toscrape.com/login)
No quotes found!
## Top Ten tags
...
```

The status is 200. A loop that stops only on an error code would keep going to page 12, 13 and on, fetching the same empty page each time. The signal is in the body, where the item list is empty. Count the items you extracted from each page, and stop on the first page that yields none. If a site answers past the end with an error code, stop on that too, but do not count on getting one.

## Guards for every walk

A next link can lead somewhere you have already been. Keep a set of the page URLs you have fetched, and stop if a next link points into it. Normalize each URL before you compare, so that a trailing slash or a reordered query string does not make one page look like two.

Ignore the fragment, the part after `#`, when you compare page URLs. Google's page says it "ignores fragment identifiers", and a pager that changes only the fragment is driving JavaScript, not loading a new page. Fetching the same address twice will give you page one twice.

Sort orders and filters multiply a list. Google advises sites "To avoid indexing variations of the same list of results", and the same reasoning applies to you. Pick one order, the default if it is stable, and walk that one. Walking every sort order fetches the same items many times over and adds load to the site for nothing.

Go at a pace a person could follow. Fetch one listing page at a time with a pause between requests, and remember that a site that sets a Crawl-delay line has told you what pause it wants. Read its [robots.txt](/learn/robots-txt/) before the first page, and read its terms if the catalogue sits behind an account.

## When the site has no pager at all

Some lists load more items when you press a button or scroll to the bottom. Google's page says that load-more buttons and "infinite scroll are generally implemented using JavaScript", and its own crawler does not press buttons. There is no next link to follow. Open the browser's network panel, press the button once, and look at the request it sends. That request is still part of the site, so check its path against robots.txt too. It may be a JSON call with a page number or a cursor, and that call has its own stop signal, such as an empty list or a missing cursor. When you can find that request, page through it with the same checks. When you cannot, a sitemap may list every item page directly, which skips the listing pages altogether.

For a list you scrape every day, add one more stop: the first item you already have. On a list sorted newest first, new items appear on page one, so a daily run can end early instead of walking the whole list again.

## Do this, avoid this

### Do this

- Stop on the first page that has no next link, and record which page that was.
- Set a page limit on every walk, and mark a run that hit it as incomplete.
- Count the items on each page, and stop when a page yields none, even with a 200.
- Keep a set of fetched page URLs and stop when a next link points back into it.
- Pick one sort order and one filter set, and walk only that.

### Avoid this

- Reporting totals from a run that hit its limit as if the list ended there.
- Stopping only on error codes. An empty page past the end can still return 200.
- Comparing page URLs without normalizing them first.
- Following page links that change only the part after the # sign.

## Run it on your own list

Change the `url` to the first listing page of a catalogue you are allowed to collect, change the `whitelist` to the path its listing pages share, and change `root_selector` to the class of its pager. Run it once with a small limit and read the last page it returned. If that page still has a next link, raise the limit and run it again.

## Sources

1. [Google Search Central, Pagination, incremental page loading, and their impact on Google Search](https://developers.google.com/search/docs/specialty/ecommerce/pagination-and-incremental-page-loading) Read November 20, 2026
2. [WHATWG HTML Standard, section 4.6 Links, the next link type](https://html.spec.whatwg.org/multipage/links.html) Read November 20, 2026
3. [RFC 8288, Web Linking, IETF, October 2017](https://www.rfc-editor.org/rfc/rfc8288.html) Read November 20, 2026
