tracker

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

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

View Source
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

type ScoredElement struct {
	Index int
	Score float64
}

ScoredElement pairs an element fingerprint with its similarity score.

type ScoredMatch

type ScoredMatch struct {
	Element *parser.Adaptable
	Score   float64
}

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 New

func New(store *storage.Store) *Tracker

New creates a new Tracker with the given storage backend.

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

func (tr *Tracker) SetThreshold(threshold float64)

SetThreshold sets the minimum similarity score for relocation.

func (*Tracker) Store

func (tr *Tracker) Store() *storage.Store

Store returns the underlying storage backend.

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.

func (*Tracker) Track

func (tr *Tracker) Track(pageURL, selectorStr string, elem *parser.Adaptable) error

Track saves an element's fingerprint for later relocation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL