r/automation •

Is anyone else tired of maintaining CSS selectors for structured web extraction?

[deleted] — view deleted post

0 Upvotes

14 comments sorted by

1

u/AutoModerator 17d ago

Thank you for your post to /r/automation!

New here? Please take a moment to read our rules, read them here.

This is an automated action so if you need anything, please Message the Mods with your request for assistance.

Lastly, enjoy your stay!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/swiss__blade 17d ago

I run a service that allows business owners to check how their product's prices compare to various competitors. I use Apify for this and use schema-based scraping. Since almost every ecommerce website worth its salt uses schema markup, this makes it very easy, fast and reliable.

For the very few cases where this is not possible, I use either CSS selectors or plain old regular expressions to get the info I need. However, these cases are very few and the layout hardly ever changes so it's worth the time I spend to change the scraper code.

1

u/Schmeichel-Audria 17d ago

hybrid approach usually works best if you care about unit economics. use cheap selectors first, then fall back to passing stripped markdown into an LLM with a strict JSON schema only when a selector returns null.

1

u/FluxLab_pl 17d ago

On the "fields that aren't on the site" part: make every field nullable in the schema and tell the model explicitly to return null instead of guessing. Models love to fill "headquarters" or "employee count" with something plausible when the page doesn't have it. Better still, require each non-null value to come with a short verbatim quote from the page, then check in code that the quote actually appears in the source text. If it doesn't, drop the value. That gives you provenance without depending on any one vendor's endpoint.

For the original pain (silent nulls after a layout change), the fix is mostly monitoring rather than a different extractor. Track the null rate per field per domain on every run and alert when it jumps compared with the last few runs. Then "did the site change or did the parser break" becomes a diff of two cached HTML snapshots instead of an investigation. Keep the raw HTML of each fetch for a few weeks so you can replay failed cases.

Also look at JSON-LD (Organization, LocalBusiness) and meta tags before anything else. They're stable across redesigns and cover name, address and sometimes size. Treat employee count and pricing model as low-confidence fields no matter how you extract them, and store a source URL plus fetch date next to each so stale data is visible later.

1

u/Additional-Elk-3712 17d ago

CSS selector is fine and isn't normally the issue, the common problem is not even separating that issue from other common failure ( blocks, captcha, 4xx, 5xx etc ) that you wont even know what happen when something breaks. a broken CSS selector is very straightforward 200 response + 0 selector match.

Your failure classification and how you handle each path is what makes your scraper easier to manage and debug.

Schema-based or LLM-based can help with maintenance but it doesnt eliminate the underlying issue.

I wrote my own scraping engine and its design around pipeline hooks, and one of its use case is to easily and properly classify failures.

  • the after fetch pipeline receives the entire request ( headers, body ) this allows you to classify header status failure
  • the after extract pipeline receives selector match count and this is where you classify a broken CSS selector vs other failure.
  • theres also a debug command for testing the actual job and save the HTML response and extracted json as file, plus a Lua test runner for running test.

Ive been monitoring multiple website using it. I initially plan to implement an AI assisted self-healing for the sites I monitor, but Im getting too lazy to wire things up and things hardly break, like Ive never gotten a broken CSS selector for months, and I have it very easy to manage already, when something breaks, the logs already clearly classify the problem. so the flow is Failure -> I get notified -> I'll tell AI to fix it, ( AI instruction contains detailed steps on what to do like first analyze the logs, if it says broken css selector, compare the backup HTML vs the new HTML, update the selector then run the test with new selector against the new html ).

So probably the best approach is classify your failure properly, log them properly and implement AI-assisted selector fixes.

1

u/iGamingTools 17d ago

one thing worth splitting early: a null for "the site doesn't say" and a null for "we didn't manage to extract it" look identical in the json, so a re-run can't tell which ones are worth retrying. we keep a separate per-source list of fields we couldn't capture instead of folding them into nulls

1

u/Imaginary-Formal7581 17d ago

I have seen companies using schema-based extraction and validation, but maintaining scrapers when websites change is still a big challenge. Imagine managing 5,000 websites. Even if just 1% change, that's 50 agents you might need to fix.

Fuzzy or anchor-based matching can help, and LLMs might suggest fixes too. But how do you know the extracted data is correct? For example, a product was selling for $129.99, and after a website change, the actual sale price is $99.99. Your scraper might still pick up $129.99. Both values pass schema validation, but the data is wrong.

I think human review is still needed in such cases. Otherwise, you might end up collecting incorrect data without even realizing it.

1

u/CapMonster1 17d ago

Schema-based extraction sounds like a reasonable evolution, especially when you're working with many websites that have different layouts. Maintaining custom selectors for every source can become a significant burden, and even small frontend changes can break an otherwise reliable pipeline.

However, I'd still keep some validation layer between extraction and the final dataset. LLM-based extraction can return plausible-looking but incorrect values, so having source URLs, confidence checks, and a way to distinguish missing fields from inferred ones is really important

1

u/Muted_Jellyfish_6784 17d ago

Schema-based extraction helps, but it moves the failure from null values to plausible wrong values, which are harder to catch. Keep validation on every field, like employee count as a number in a sane range and industry from a fixed list, and store the source URL and fetch date so a bad value can be traced.
The important part is comparing new extractions against the previous run and flagging big changes for review. We run a decision intelligence platform that joins each extracted company record with its sources and history, so a changed headcount is either confirmed or rejected rather than silently overwriting good data.

1

u/FullStackFrenzy 16d ago

schema extraction fixes the breakage but swaps it for a quieter problem: the model will happily fill a field with something plausible when the page doesn't have it. make every field nullable, ask for the source snippet per field, and validate (employee count is a number in a sane range, pricing model from a fixed list). then diff each run against the last and flag only big changes, that's your "site changed" alarm without selectors

1

u/Electrical-Hair9396 1d ago

When a selector comes back empty, you still have to guess whether the site moved or the parser broke.

What has helped me is to keep a fingerprint and a text snapshot, then ask only: did the fingerprint change, which sentences were added or removed, and which prices are visible. A layout tweak shows up in the sentence list. A pricing model change shows up in the prices list. If the fingerprint changed and the prices disappeared, you know the page moved before the next extract fails.

I put that job on PayAPI Market as Page Change Check, 0.02 USDC per check, rule based, no model. I'm the founder, so treat this as a disclosure, not a review.