Documentation
¶
Overview ¶
Package tracker provides adaptive element tracking with multi-factor similarity scoring. When a website changes its DOM structure, the tracker can relocate previously-tracked elements by comparing stored fingerprints against current page elements.
Index ¶
- Constants
- func CalculateSimilarityScore(stored, candidate *storage.ElementDict) float64
- func ElementToDict(a *parser.Adaptable) *storage.ElementDict
- type ScoredElement
- type ScoredMatch
- type Tracker
- func (tr *Tracker) Find(root *parser.Adaptable, pageURL, cssSelector string) (*parser.Adaptable, error)
- func (tr *Tracker) Relocate(root *parser.Adaptable, pageURL, identifier string) (*parser.Adaptable, error)
- func (tr *Tracker) RelocateAll(root *parser.Adaptable, pageURL, identifier string) ([]*ScoredMatch, error)
- func (tr *Tracker) SetThreshold(threshold float64)
- func (tr *Tracker) Store() *storage.Store
- func (tr *Tracker) TopMatches(root *parser.Adaptable, pageURL, identifier string, n int) ([]*ScoredMatch, error)
- func (tr *Tracker) Track(pageURL, selectorStr string, elem *parser.Adaptable) error
Constants ¶
const DefaultThreshold = 50.0
DefaultThreshold is the minimum similarity score for relocation to succeed.
Variables ¶
This section is empty.
Functions ¶
func CalculateSimilarityScore ¶
func CalculateSimilarityScore(stored, candidate *storage.ElementDict) float64
CalculateSimilarityScore computes a weighted similarity score between a stored element fingerprint and a candidate element fingerprint. Returns a score from 0 to 100.
func ElementToDict ¶
func ElementToDict(a *parser.Adaptable) *storage.ElementDict
ElementToDict converts an Adaptable element into an ElementDict fingerprint for storage. This captures tag, text, attributes, DOM path, parent info, sibling tags, and child tags.
Types ¶
type ScoredElement ¶
ScoredElement pairs an element fingerprint with its similarity score.
type ScoredMatch ¶
ScoredMatch pairs an element with its similarity score.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker manages element fingerprinting and adaptive relocation.
func (*Tracker) Find ¶
func (tr *Tracker) Find(root *parser.Adaptable, pageURL, cssSelector string) (*parser.Adaptable, error)
Find attempts to find an element using CSS selector first, then falls back to fingerprint-based relocation if the selector fails.
func (*Tracker) Relocate ¶
func (tr *Tracker) Relocate(root *parser.Adaptable, pageURL, identifier string) (*parser.Adaptable, error)
Relocate attempts to find the best-matching element on the page using stored fingerprints and multi-factor similarity scoring.
func (*Tracker) RelocateAll ¶
func (tr *Tracker) RelocateAll(root *parser.Adaptable, pageURL, identifier string) ([]*ScoredMatch, error)
RelocateAll returns all elements above threshold, sorted by score descending.
func (*Tracker) SetThreshold ¶
SetThreshold sets the minimum similarity score for relocation.
func (*Tracker) TopMatches ¶
func (tr *Tracker) TopMatches(root *parser.Adaptable, pageURL, identifier string, n int) ([]*ScoredMatch, error)
TopMatches returns the top N matches for relocation.