<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>124</id><slug>building-a-polite-scrapy-spider-part-7-124</slug><title>Building a polite Scrapy spider, part 7</title><excerpt>For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. Scrapy makes it very easy to send thousands of requests a minute. Making a spider that a site operator…</excerpt><seriesName>Building a polite Scrapy spider</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. Scrapy makes it very easy to send thousands of requests a minute. Making a spider that a site operator would be happy to see in their logs takes a few deliberate settings.</item></paragraphs></item><item><heading>Common pitfalls</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>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</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></paragraphs></item><item><heading>A practical approach</heading><paragraphs><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><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>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></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Turn on ROBOTSTXT_OBEY, set AutoThrottle, use a descriptive User-Agent with contact details, and cache responses while you develop.</item></paragraphs></item></sections><authorId>4</authorId><authorName>Lucas Silva</authorName><authorSlug>lucas-silva</authorSlug><category>Scraping Basics</category><tags><item>http</item><item>python</item><item>ethics</item><item>scrapy</item></tags><publishedAt>2025-06-19T00:00:00.000Z</publishedAt><wordCount>248</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
