Change Detection

The Watch system detects changes in extracted fields over time by comparing current extraction results against stored baselines.

4 min read Updated July 2026

Change Types

ContentChange

Triggered when text content differs from baseline.

python
1watch.field("title", "h1")

PriceChange

Specialized numeric change detection with percentage calculation and tolerance thresholds.

python
1watch.field("price", "span.price", extraction_type="price")
2watch.tolerance(0.05) # Only fires if price changes by > 5%

StockChange

Triggered when availability indicators change.

python
1watch.field("stock", ".availability-badge")

ElementAdded / ElementRemoved

Triggered when a selector starts matching new elements or stops matching existing ones.

python
1watch.field("items", ".product-item")

Event Object Structure

event.json
python
1{
2 "field": "price", # Changed field name
3 "old_value": "299.99", # Previous baseline value
4 "new_value": "249.99", # Current value
5 "change_type": "PriceChange",
6 "change_pct": -16.67, # Percentage change (numeric fields)
7 "url": "https://example.com/product/1",
8 "timestamp": "2026-07-26T10:30:00Z"
9}

Low-Level Change Detection Function

detect.py
python
1from crawlingo import detect_changes
2
3old_data = {"price": "299.99", "title": "Widget"}
4new_data = {"price": "249.99", "title": "Widget"}
5
6changes = detect_changes("https://example.com", old_data, new_data)
7for change in changes:
8 print(f"{change.field}: {change.change_type} ({change.old_value} → {change.new_value})")

Integration with Webhooks

webhook.py
python
1import requests
2from crawlingo import Watch
3
4def on_change(event):
5 requests.post("https://my-api.example.com/webhook", json={
6 "field": event.field,
7 "old_value": event.old_value,
8 "new_value": event.new_value,
9 "change_type": event.event_type,
10 "url": event.url,
11 })
12
13Watch("https://example.com")\
14 .field("price", "span.price", extraction_type="price")\
15 .interval(300)\
16 .on_change(on_change)