Ask a scraper author where their dataset lost 30% of its records, and the answer is usually pagination: the loop stopped early, the site capped results, or infinite scroll hid everything past screen one. Pagination is where scrapers silently fail — here's how each pattern works and how to handle it.
The classic ?page=2. The mistake is trusting the advertised page count. Loop until the site actually stops yielding:
page, items = 1, []
while True:
batch = fetch_page(page)
if not batch: # empty page = the real end
break
items.extend(batch)
page += 1
Watch for the result cap: many sites serve at most N pages regardless of matches (search engines and portals especially). If total results exceed the cap, shard the query — by category, price band, or geography — until each shard fits under it.
APIs return a next_cursor or continuation token with each response. Follow the token, never invent offsets — cursors tolerate inserts/deletes mid-crawl, which offset math does not:
cursor = None
while True:
data = fetch(cursor=cursor)
items.extend(data["results"])
cursor = data.get("next_cursor")
if not cursor:
break
Infinite scroll is almost always a cursor API wearing a UI costume. Open the network tab, scroll, and copy the XHR request the page makes — then paginate that endpoint directly with HTTP instead of driving a browser. Only when the requests are cryptographically signed or heavily obfuscated is browser automation (Playwright scrolling) worth its cost.
Open the browser network tab and scroll: the page fires an API request per batch. Replicate that request in Python and follow its cursor parameter — far faster and more reliable than automating actual scrolling.
Many sites cap accessible results per query regardless of total matches. Split the query into narrower shards (by category, price range, or location) so each shard fits under the cap.
I build scrapers, Actors, and data pipelines as a service — fixed quote, fast turnaround.
Start a project →