<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>150</id><slug>choosing-css-selectors-that-survive-redesigns-part-8-150</slug><title>Choosing CSS selectors that survive redesigns, part 8</title><excerpt>Part 8 looks at what changes when the same technique has to run every day in production. A selector that worked yesterday and fails today is usually a selector that depended on something nobody…</excerpt><seriesName>Choosing CSS selectors that survive redesigns</seriesName><seriesPart>8</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>Part 8 looks at what changes when the same technique has to run every day in production. A selector that worked yesterday and fails today is usually a selector that depended on something nobody promised to keep the same, such as a generated class name or the position of a div.</item></paragraphs></item><item><heading>Putting it into practice</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>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>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>What to watch for</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>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Prefer data-testid attributes, ARIA roles and visible labels. Avoid long chains of nth-child and anything that looks like a hash.</item></paragraphs></item></sections><authorId>8</authorId><authorName>Hannah Novak</authorName><authorSlug>hannah-novak</authorSlug><category>Testing</category><tags><item>javascript</item><item>playwright</item><item>testing</item></tags><publishedAt>2024-10-06T00:00:00.000Z</publishedAt><wordCount>212</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
