<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>49</id><slug>rate-limit-headers-explained-part-3-49</slug><title>Rate limit headers explained, part 3</title><excerpt>This is part 3 of our series, and this time we focus on edge cases readers asked about. A well-behaved API tells you how many requests you have left before it starts saying no. Reading those headers…</excerpt><seriesName>Rate limit headers explained</seriesName><seriesPart>3</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>This is part 3 of our series, and this time we focus on edge cases readers asked about. A well-behaved API tells you how many requests you have left before it starts saying no. Reading those headers turns rate limiting from a surprise into a plan.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><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><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>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>Common pitfalls</heading><paragraphs><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>Log every request with its URL, status code and duration. When something goes wrong at two in the morning, those logs are the difference between a quick fix and a long investigation.</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>Track X-RateLimit-Remaining, slow down as it approaches zero, and when you receive a 429, wait for the number of seconds in Retry-After before trying again.</item></paragraphs></item></sections><authorId>12</authorId><authorName>Yuki Andersson</authorName><authorSlug>yuki-andersson</authorSlug><category>APIs</category><tags><item>python</item><item>http</item><item>scrapy</item><item>testing</item></tags><publishedAt>2024-03-31T00:00:00.000Z</publishedAt><wordCount>240</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
