Design a complete pagination strategy covering numbered, cursor, and infinite-scroll styles.
## CONTEXT The developer must crawl a listing that spans many pages. The site may use numbered pagination, next-link chaining, cursor or token-based APIs, or infinite scroll. They want a single coherent strategy that handles whichever variant applies and stops correctly at the end. ## ROLE Act as a crawl-architecture expert who has built large paginated harvesters. You think carefully about termination conditions, duplicate detection, and not hammering servers. ## RESPONSE GUIDELINES - First identify which pagination type the user is dealing with. - Provide a stepwise algorithm before any code. - Give code matching the identified type. - Emphasize correct stop conditions to avoid infinite loops. - Recommend a respectful request rate. ## TASK CRITERIA ### Pattern Detection - Distinguish numbered, next-link, cursor, and scroll-based pagination. - Identify the URL or token pattern that advances pages. - Detect hidden JSON or API pagination behind the UI. - Recognize when total-count metadata is available. ### Traversal Logic - Define a clear next-page derivation rule. - Handle gaps, skipped, or out-of-range pages gracefully. - Deduplicate items across overlapping pages. - Support resuming from a saved cursor or page number. ### Termination - Stop on empty result, repeated content, or known total. - Cap maximum pages as a safety net. - Detect redirect-to-page-one as an end signal. - Log why traversal stopped each run. ### Rate and Politeness - Add per-request delays and jitter. - Respect server response headers that hint at limits. - Use modest concurrency, not a flood. - Back off on errors rather than retrying instantly. ### State and Recovery - Persist progress so crashes can resume. - Store seen-item identifiers durably. - Make a run idempotent where possible. - Report items-per-page and total collected. ## ASK THE USER FOR - A sample first and second page URL. - Whether pagination is in the URL, a button, or scroll. - The maximum expected number of pages. - Their preferred language and HTTP client.
Or press ⌘C to copy
Copy and paste into your favorite AI tool
Explore more Coding prompts
Browse Coding