How to Scrape Pagination and Infinite Scroll Pages Without Missing or Duplicating Results
web scrapingpaginationinfinite scrolldata extractionautomation

How to Scrape Pagination and Infinite Scroll Pages Without Missing or Duplicating Results

WWebscraper.live Editorial Team
2026-11-30
7 min read

A practical checklist for scraping numbered pages, next links, load-more buttons, and infinite scroll without gaps or duplicates.

Pagination is easy to underestimate: a scraper can finish without errors while silently skipping pages, repeating records, or stopping before JavaScript-rendered results appear. This checklist explains how to scrape numbered pagination, next-page links, load-more controls, and infinite-scroll interfaces with repeatable stopping rules, deduplication, validation, and troubleshooting steps.

Overview

Before writing a loop, identify how the interface represents progress. A traditional results page may expose URLs such as ?page=2 or a link labelled “Next.” A load-more interface may request another batch after a button click. Infinite scroll often uses a browser event to trigger a background request, with the visible page acting as a shell around JSON data.

The most reliable workflow is to separate discovery, extraction, and validation:

  1. Discover the page model. Inspect links, query parameters, forms, buttons, cursors, and network requests.
  2. Define a stable record key. Prefer a product ID, article URL, database ID, or another field that should remain unique.
  3. Choose the least complex collection method. Use direct HTTP requests when complete data is available in the HTML or a public endpoint. Use a browser only when rendering or interaction is required.
  4. Set explicit stopping conditions. Do not rely on an arbitrary page limit as the only safeguard.
  5. Validate the result set. Check counts, duplicate keys, missing fields, page transitions, and the final response.

Pagination logic is part of the frontend workflow, not just a transport detail. A redesign can change a button into a link, replace page numbers with cursors, or move the data from server-rendered HTML into a client-side request. Keeping discovery and extraction separate makes those changes easier to diagnose.

Checklist by scenario

Start with the simplest pattern. Fetch the first page, extract its records, locate the next link, and repeat until the next link is absent or points to a URL already visited. Resolve relative links against the current page URL rather than concatenating strings manually.

from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup

url = "https://example.com/catalog"
visited = set()
records = {}

while url and url not in visited:
    visited.add(url)
    response = requests.get(url, timeout=30)
    response.raise_for_status()
    soup = BeautifulSoup(response.text, "html.parser")

    for card in soup.select("article.card"):
        link = card.select_one("a.card-link")
        if not link:
            continue
        item_url = urljoin(url, link.get("href"))
        records[item_url] = {
            "url": item_url,
            "title": card.select_one(".title").get_text(" ", strip=True)
        }

    next_link = soup.select_one("a[rel='next'], a.next-page")
    url = urljoin(url, next_link["href"]) if next_link and next_link.get("href") else None

The dictionary provides a basic deduplication layer. In production, record the page URL and collection timestamp as well, so you can identify where a duplicate or missing item originated.

Query-parameter pagination

Some sites do not expose a usable next link, but the page number is predictable. Confirm that assumption with a small test: compare the first few responses, inspect whether the page parameter changes the content, and check what happens beyond the apparent last page. Use URL-building tools rather than string replacement so existing parameters are preserved.

A page-number loop should stop when one of these conditions is met:

  • The response contains no result cards.
  • The extracted record count is zero.
  • The page repeats a previously seen set of stable keys.
  • The response explicitly indicates that no further page exists.
  • A known total has been reached, with a validation check afterward.

Load-more buttons

A load-more button can be a browser-only control, but it may also reveal a straightforward endpoint in its HTML attributes or JavaScript configuration. Inspect attributes such as data-page, data-offset, data-url, or data-cursor. If the button triggers a JSON request, collecting that response directly is usually easier to test than repeatedly parsing the rendered DOM.

If interaction is necessary, wait for a measurable change after each click. A safe browser-driven loop checks that either the number of records increases, the button becomes disabled, a loading indicator disappears, or a “no more results” state appears. A fixed number of clicks is useful as a safety ceiling, but it should not be the primary stopping rule.

Infinite scroll

Infinite scroll is often best treated as an API-discovery problem. Open browser developer tools, observe the network requests while scrolling, and identify requests whose response contains the next batch. Look for an offset, page number, cursor, or continuation token. Capture the request method, required parameters, response shape, and the condition that indicates the final batch.

If no usable endpoint is available, a Playwright or Puppeteer workflow can scroll the page and wait for new content. Track the stable keys already collected, not just the height of the document. A page can increase in height without adding records, and virtualized lists can remove old nodes from the DOM while keeping the total result count unchanged. For tool-selection considerations, see Playwright vs Puppeteer for Web Scraping.

Cursor-based pagination

Cursor pagination requires carrying a value returned by the previous response into the next request. Store each cursor, reject a cursor that has already been used, and stop when the response omits the continuation value or marks the batch as final. Do not assume that cursors can be generated by incrementing a number; they may be opaque and valid only for a particular query or session.

What to double-check

  • Record identity: Choose a key that is stable across pages and runs. A title alone may not be unique; a canonical URL or source ID is usually stronger.
  • Page transitions: Log the current URL, next URL, page number, cursor, HTTP status, and extracted count. These fields make repeated-page errors visible.
  • HTML versus rendered data: View the raw response as well as the browser DOM. Content present only after JavaScript runs requires a different collection strategy.
  • Request state: Check whether the next request depends on cookies, headers, a form token, or a session. Replaying an incomplete request can return the same first batch repeatedly.
  • Partial responses: Treat timeouts, rate-limit responses, redirects, and empty responses differently from a legitimate final page. Retrying without logging can turn an error into an apparent end of data.
  • Ordering: Save the source page and position for every record. If the site changes ordering during a long run, you can detect overlaps or gaps during review.
  • Scope and permissions: Follow the target site's published instructions, use a reasonable request rate, and collect only data you are permitted to access. The workflow in How to Scrape a Website Responsibly covers the surrounding operational checks.

For quality control, compare the observed count with any visible total, export a duplicate report, and sample records from the beginning, middle, and end of the run. If the output feeds a technical SEO workflow, also check canonical URLs, status codes, and indexability using the approach described in Technical SEO Crawling with Python.

Common mistakes

SymptomLikely causePractical fix
The same records appear on every pageThe page parameter is ignored, or the request lacks required state.Compare response URLs and bodies, inspect the actual browser request, and verify the parameter or cursor is being sent.
The scraper stops too earlyIt treats an empty response, temporary error, or unchanged DOM as the final page.Distinguish terminal states from failures and retry transient errors with a bounded policy.
Infinite scroll returns partial resultsThe script scrolls before the previous request finishes, or virtualized content is mistaken for the complete DOM.Wait for a specific response or record-count change and prefer the underlying data request when possible.
Results contain duplicatesPages overlap, the cursor repeats, or the scraper clicks a control more than once.Maintain a set or dictionary of stable keys and stop on a repeated cursor or page signature.
Some fields are blankSelectors match multiple layouts, content is lazy-loaded, or the request returned an error page.Validate required fields, save failed HTML for inspection, and use fallback selectors only when their meaning is clear.
The browser loop runs foreverThere is no explicit maximum, or the page keeps emitting non-record UI changes.Set a safety ceiling for pages, clicks, requests, and runtime, while retaining data-based stopping conditions.

Keep a small fixture from each pagination mode and test it after selector or library changes. The guide to testing web scrapers with Python provides useful patterns for fixtures, golden files, and regression checks.

When to revisit

Revisit pagination logic whenever the target site changes its frontend, introduces a new results layout, changes its URL structure, or moves data from server-rendered HTML to a client-side request. Also review it before seasonal planning cycles or any scheduled collection run that supports a time-sensitive report. A scraper that worked last month may still return HTTP 200 responses while collecting incomplete data.

Use this short pre-run checklist:

  1. Load the first page manually and confirm the visible result structure.
  2. Inspect one transition to the next page, batch, or cursor.
  3. Confirm the stable record key and deduplication behavior.
  4. Run a small sample with detailed logging before the full collection.
  5. Compare counts and duplicate totals with the previous successful run.
  6. Save enough request and page metadata to reproduce a failure.

When a redesign breaks the workflow, begin with discovery rather than adding more delays or selectors. Check whether a public JSON endpoint now carries the same records; discovering public JSON endpoints can reduce browser complexity. Then update the fixture, stopping rules, and validation report together. That final step keeps the scraper from merely running again—it helps establish that it is still collecting the complete, non-duplicated result set.

Related Topics

#web scraping#pagination#infinite scroll#data extraction#automation
W

Webscraper.live Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.