<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>51</id><slug>xpath-for-nested-structures-part-3-51</slug><title>XPath for nested structures, part 3</title><excerpt>Part 3 looks at what changes when the same technique has to run every day in production. When the data you want is several levels deep and the markup has few useful attributes, XPath's ability to…</excerpt><seriesName>XPath for nested structures</seriesName><seriesPart>3</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>Part 3 looks at what changes when the same technique has to run every day in production. When the data you want is several levels deep and the markup has few useful attributes, XPath's ability to navigate up, down and sideways through the tree becomes very handy.</item></paragraphs></item><item><heading>Step by step</heading><paragraphs><item>Be careful with relative URLs. Resolve every link against the page it came from, not against the site root, or you will request pages that do not exist.</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>Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.</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>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>Key takeaway</heading><paragraphs><item>Anchor on a stable nearby element, then use relative paths and axes such as following-sibling and ancestor rather than absolute paths from the root.</item></paragraphs></item></sections><authorId>6</authorId><authorName>Sofia Fischer</authorName><authorSlug>sofia-fischer</authorSlug><category>Scraping Basics</category><tags><item>scrapy</item><item>javascript</item><item>json</item><item>ethics</item></tags><publishedAt>2026-09-10T00:00:00.000Z</publishedAt><wordCount>202</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
