{"data":{"id":90,"slug":"choosing-css-selectors-that-survive-redesigns-part-5-90","title":"Choosing CSS selectors that survive redesigns, part 5","excerpt":"For part 5, we revisit the basics with a fresh example and a few lessons learned the hard way. 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":5,"sections":[{"heading":"Introduction","paragraphs":["For part 5, we revisit the basics with a fresh example and a few lessons learned the hard way. 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.","Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream."]},{"heading":"Going further","paragraphs":["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.","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.","Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them."]},{"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":5,"authorName":"Chen Patel","authorSlug":"chen-patel","category":"Testing","tags":["python","json","http"],"publishedAt":"2025-07-03T00:00:00.000Z","wordCount":243,"readingTimeMinutes":2}}