{"data":{"id":31,"slug":"xpath-for-nested-structures-part-2-31","title":"XPath for nested structures, part 2","excerpt":"In part 2 we take the ideas from earlier instalments and apply them to a larger, messier site. When the data you want is several levels deep and the markup has few useful attributes, XPath's ability…","seriesName":"XPath for nested structures","seriesPart":2,"sections":[{"heading":"Introduction","paragraphs":["In part 2 we take the ideas from earlier instalments and apply them to a larger, messier site. 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."]},{"heading":"Common pitfalls","paragraphs":["Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them.","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.","Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream."]},{"heading":"Putting it into practice","paragraphs":["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.","Before writing a single line of code, look at how the page actually loads its data. Open the network panel, reload, and note which requests return the content you care about. Very often the data you want arrives as JSON from an endpoint you can call directly.","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."]},{"heading":"Key takeaway","paragraphs":["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."]}],"authorId":5,"authorName":"Chen Patel","authorSlug":"chen-patel","category":"Scraping Basics","tags":["playwright","ethics"],"publishedAt":"2026-09-12T00:00:00.000Z","wordCount":247,"readingTimeMinutes":2}}