Documentation
¶
Overview ¶
Example: adaptive selectors that survive DOM changes.
Adaptive selectors learn an element signature on first successful match. On future runs, even when the producer renames or restructures the containing CSS class, similarity matching falls back to the saved signature so the scraper keeps working without code changes.
This example demonstrates the inline Response API on a static HTML fixture so it can be run without network access:
- Run 1: original markup with class "product" — selector matches, signature is learned and persisted to ./adaptive_signatures.json
- Run 2: same page but the class has been renamed to "item" — CSS selector finds nothing, but Response.Adaptive() falls back to the saved signature and still extracts the price
Run:
go run ./examples/adaptive/
Click to show internal directories.
Click to hide internal directories.