<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>136</id><slug>detecting-lazy-loaded-content-part-7-136</slug><title>Detecting lazy-loaded content, part 7</title><excerpt>For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. Lazy loading defers images and sections until they are about to scroll into view. A script that reads…</excerpt><seriesName>Detecting lazy-loaded content</seriesName><seriesPart>7</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. Lazy loading defers images and sections until they are about to scroll into view. A script that reads the page immediately sees placeholders instead of content.</item></paragraphs></item><item><heading>Step by step</heading><paragraphs><item>Dynamic pages render content after the initial HTML arrives. A browser automation tool can wait for a specific element to appear, which is far more reliable than sleeping for a fixed amount of time.</item><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>Write small, focused tests for your parsers using saved HTML fixtures. They run in milliseconds and catch layout changes long before a full crawl would.</item></paragraphs></item><item><heading>Putting it into practice</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>Treat HTTP 429 responses as a signal, not an obstacle. Read the Retry-After header, back off, and resume at a slower pace.</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></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Scroll the element into view and wait for its real attributes to appear, or read the data-src style attributes that hold the eventual values.</item></paragraphs></item></sections><authorId>2</authorId><authorName>Noah Bennett</authorName><authorSlug>noah-bennett</authorSlug><category>Browser Automation</category><tags><item>scrapy</item></tags><publishedAt>2024-03-11T00:00:00.000Z</publishedAt><wordCount>240</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
