{"data":{"id":10,"slug":"choosing-css-selectors-that-survive-redesigns-10","title":"Choosing CSS selectors that survive redesigns","excerpt":"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.","seriesName":"Choosing CSS selectors that survive redesigns","seriesPart":1,"sections":[{"heading":"Introduction","paragraphs":["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":"What to watch for","paragraphs":["Treat HTTP 429 responses as a signal, not an obstacle. Read the Retry-After header, back off, and resume at a slower pace.","Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.","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."]},{"heading":"Step by step","paragraphs":["Store raw responses alongside parsed output while you are developing. When a parser breaks, you can replay the saved HTML instead of hitting the site again.","Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator."]},{"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":7,"authorName":"Kwame Mensah","authorSlug":"kwame-mensah","category":"Testing","tags":["ethics","http","json","testing"],"publishedAt":"2023-11-25T00:00:00.000Z","wordCount":182,"readingTimeMinutes":2}}