{"data":{"id":130,"slug":"choosing-css-selectors-that-survive-redesigns-part-7-130","title":"Choosing CSS selectors that survive redesigns, part 7","excerpt":"In part 7 we take the ideas from earlier instalments and apply them to a larger, messier site. 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":7,"sections":[{"heading":"Introduction","paragraphs":["In part 7 we take the ideas from earlier instalments and apply them to a larger, messier site. 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":"A practical approach","paragraphs":["Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.","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."]},{"heading":"Common pitfalls","paragraphs":["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.","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."]},{"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":1,"authorName":"Amelia Okafor","authorSlug":"amelia-okafor","category":"Testing","tags":["javascript","selenium","http"],"publishedAt":"2026-04-12T00:00:00.000Z","wordCount":186,"readingTimeMinutes":2}}