<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>162</id><slug>handling-infinite-scroll-in-playwright-part-9-162</slug><title>Handling infinite scroll in Playwright, part 9</title><excerpt>For part 9, we revisit the basics with a fresh example and a few lessons learned the hard way. Infinite scroll replaces the familiar Next button with a page that keeps growing as you move down it,…</excerpt><seriesName>Handling infinite scroll in Playwright</seriesName><seriesPart>9</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 9, we revisit the basics with a fresh example and a few lessons learned the hard way. Infinite scroll replaces the familiar Next button with a page that keeps growing as you move down it, which means your script has to decide when there is nothing left to load.</item></paragraphs></item><item><heading>A practical approach</heading><paragraphs><item>Pagination comes in several shapes: numbered pages, next links, offsets and opaque cursors. Each has trade-offs, and a robust scraper should detect the end of the result set rather than assuming a fixed number of pages.</item><item>Read the site's terms of service before you start. Many sites welcome automated access within limits and say so explicitly; others ask you to use an API instead.</item><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item></paragraphs></item><item><heading>Going further</heading><paragraphs><item>Deduplicate as you go. The same item often appears on several listing pages, and a stable identifier such as a SKU or ID makes duplicates easy to spot.</item><item>Store raw responses alongside parsed output while you are developing. When a parser breaks, you can replay the saved HTML instead of hitting the site again.</item><item>Selectors are the most fragile part of any scraper. Prefer stable attributes such as data-testid or semantic structure over generated class names, which can change on every deploy.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Scroll, wait for the item count to change, and stop when two consecutive scrolls add nothing new. Better still, find the JSON request the page makes and call it directly.</item></paragraphs></item></sections><authorId>9</authorId><authorName>Mateo Hughes</authorName><authorSlug>mateo-hughes</authorSlug><category>Browser Automation</category><tags><item>http</item><item>javascript</item><item>testing</item><item>python</item></tags><publishedAt>2024-02-29T00:00:00.000Z</publishedAt><wordCount>248</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
