<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>37</id><slug>reading-sitemaps-to-discover-urls-part-2-37</slug><title>Reading sitemaps to discover URLs, part 2</title><excerpt>For part 2, we revisit the basics with a fresh example and a few lessons learned the hard way. Before you crawl a site link by link, check whether it already publishes a list of every page it wants…</excerpt><seriesName>Reading sitemaps to discover URLs</seriesName><seriesPart>2</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 2, we revisit the basics with a fresh example and a few lessons learned the hard way. Before you crawl a site link by link, check whether it already publishes a list of every page it wants found. That list is usually called sitemap.xml.</item></paragraphs></item><item><heading>Going further</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>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>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></paragraphs></item><item><heading>A practical approach</heading><paragraphs><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>Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Look for the Sitemap line in robots.txt, follow sitemap index files to their children, and use lastmod to skip pages that have not changed.</item></paragraphs></item></sections><authorId>2</authorId><authorName>Noah Bennett</authorName><authorSlug>noah-bennett</authorSlug><category>Scraping Basics</category><tags><item>http</item><item>javascript</item></tags><publishedAt>2024-05-08T00:00:00.000Z</publishedAt><wordCount>228</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
