Expand description
adaptive-selector — CSS selectors that survive website redesigns.
A faithful Rust port of Scrapling’s adaptive relocation engine. Save an element’s fingerprint once; when the page changes and your CSS selector breaks, relocate the element by structural similarity instead of by selector.
use adaptive_selector::{AdaptiveDocument, SimilarityThreshold};
let doc = AdaptiveDocument::parse(r#"<div class="price">$9.99</div>"#);
let saved = doc.css_first(".price").unwrap().expect("price exists").fingerprint();
// ... the site redesigns, `.price` is now `.product-price__current` ...
let doc2 = AdaptiveDocument::parse(r#"<span class="product-price__current">$9.99</span>"#);
let found = doc2.relocate(&saved, SimilarityThreshold::default());
assert_eq!(found.first().map(|e| e.text()), Some("$9.99".to_string()));Structs§
- Adaptive
Document - A parsed HTML document with adaptive-relocation support.
- Adaptive
Element - A located element: the scraper
ElementRefplus its owner document’s tree. - Element
Fingerprint - A serialized element fingerprint — everything the similarity scorer needs. Store it anywhere (file, DB, JSON column); it is plain data.
- Similarity
Threshold - Minimum similarity (0–100) for
AdaptiveDocument::relocateto accept a candidate. Scrapling’s default is 40.
Enums§
- Error
- Errors returned by selector parsing and relocation.
Functions§
- str_
ratio - Convenience for strings — mirrors
SequenceMatcher(None, a, b).ratio()including difflib’s autojunk behavior on long B sequences.