{"data":{"id":150,"slug":"choosing-css-selectors-that-survive-redesigns-part-8-150","title":"Choosing CSS selectors that survive redesigns, part 8","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…","seriesName":"Choosing CSS selectors that survive redesigns","seriesPart":8,"sections":[{"heading":"Introduction","paragraphs":["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."]},{"heading":"Putting it into practice","paragraphs":["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.","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.","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."]},{"heading":"What to watch for","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.","Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy."]},{"heading":"Key takeaway","paragraphs":["Prefer data-testid attributes, ARIA roles and visible labels. Avoid long chains of nth-child and anything that looks like a hash."]}],"authorId":8,"authorName":"Hannah Novak","authorSlug":"hannah-novak","category":"Testing","tags":["javascript","playwright","testing"],"publishedAt":"2024-10-06T00:00:00.000Z","wordCount":212,"readingTimeMinutes":2}}