Brief & Hire
Basics

What is a CSS selector, and why does a scraper break when the site changes?

What it is, in plain words

A web page is a document with a structure: boxes inside boxes, each with a name. A CSS selector is a way of writing an address into that structure. “The number inside the box called price, inside the box called product-card” is a selector in plain words. The scraper follows that address, reads what it finds there, and puts it in your spreadsheet.

Think of a postal address. “Second floor, third door on the left” works until the building is renovated. Nobody tells the postman. The letter is delivered to a wall, or to whoever now lives behind the third door.

That is what happens to a scraper when a site changes. The site’s developers rename a box, move the price into a different one, or rebuild the page for mobile. Your scraper still follows the old address. It finds nothing, and writes an empty cell. Or it finds something else, and writes the wrong thing into the right column.

A few words you will hear around this:

  • HTML or the DOM: the document and its boxes, as the browser sees them.
  • Class or ID: the names on the boxes. Selectors are mostly written against these.
  • XPath: a second way of writing addresses, used for the same purpose.
  • Layout change or redesign: the site moving its boxes around, which breaks selectors.

A concrete example

I collect data from pages on a freelance marketplace for this kind of work: reviews, ratings and seller details, read by a small collector that runs in my browser. Everything it reads, it finds by an address inside the page.

In October 2026 one of those addresses stopped pointing at anything. The marketplace removed the “Last delivery” line from its seller pages. I had been using that line as a freshness check, to see whether a seller had delivered an order recently. The pages still loaded, nothing errored, and the field was simply gone.

The fix was not a new selector for the same line, because the line no longer existed. I had to choose a different signal that was still on the page: the date of the most recent review the page renders. That is a worse measure, since the page shows only a sample of reviews, and I wrote that down so I would read the new numbers conservatively.

The same round of checks taught a second lesson about addresses. The page also shows an “Away” badge in its message box, which I had read as “on vacation”. It only means the seller is not online at that moment. Vacation is a separate flag elsewhere in the page. The selector was finding the badge correctly; I had attached the wrong meaning to it.

And once before, the same collector read a page’s structure correctly and still produced wrong data, because a “Show More” button loaded some reviews twice. I published an inflated count and corrected it the same day.

Three different failures, no crash in any of them: an address that went dead, an element that meant something else, and a page that behaved differently from what I assumed.

Why it matters when you hire someone

You will not write selectors. But every scraper you pay for is a bundle of them, and four things go wrong when the buyer does not know this:

  1. “It works” is a snapshot. The demo ran against the site as it was that day. The site can change next week. For a one-off pull this does not matter. For a scraper that runs on a schedule, it is the main running cost, which is why maintenance terms belong in a scraping order from the start.
  2. Breakage is usually silent. A dead selector returns an empty value, not an error. The job finishes, the file lands, and the rows are blank or stale. Without a check on empty fields or row counts, you keep trusting the output.
  3. Wrong is worse than empty. When a site moves things around, a selector can land on a neighbouring value: last month’s price, a different product’s rating, a badge that means something else. Those rows look full and are wrong.
  4. The fix needs the code. If the freelancer kept the scraper on their machine, you cannot even see which address broke. Ask for the script in the hand-back, as the data scraping brief does.

A scraper that keeps retrying a dead address also sends extra requests, which is how it runs into rate limits. And a redesign sometimes comes with new rules, so the robots.txt and terms are worth rereading afterwards.

What to ask the freelancer

Add these to the “Edge cases” and “When the site changes” fields of the data scraping brief:

A good answer admits that the site will change and describes how the scraper will tell you. If the answer is “it is very robust, it will not break”, ask what it does on the day the price box gets renamed.

Questions people ask

Why did my scraper stop returning data when nothing changed on my side?

The website changed. A scraper finds each field by its position or name inside the page, and a redesign, an A/B test or a renamed element breaks that match. The scraper is usually fine; its map of the page is out of date.

Can a scraper be built so it never breaks when the site changes?

No. It can be built to break loudly instead of quietly: fail or alert when an expected field is empty, when the row count drops, or when a page looks different from the last run. That is what to ask for.

Is fixing a broken selector a quick job?

Often, if the freelancer still has the code and the site made a small change. Finding what changed takes longer than the edit, and a full redesign can mean rewriting most of the scraper. Agree the fix rate before it happens.

Where this comes up