Watch API

The Watch class periodically polls a web page and detects changes in extracted fields. It supports typed callbacks for content, price, stock, and structural changes.

5 min read Updated July 2026

Python Usage

watch.py
python
1from crawlingo import Watch
2import asyncio
3
4def on_change(event):
5 print(f"[{event.event_type}] '{event.field}' changed!")
6 print(f" Old: {event.old_value}")
7 print(f" New: {event.new_value}")
8
9async def main():
10 watcher = (
11 Watch("https://example.com/product/1")
12 .field("title", "h1")
13 .field("price", "span.price", extraction_type="price")
14 .interval(60) # Poll every 60 seconds
15 .on_change(on_change)
16 )
17
18 watch_task = asyncio.create_task(watcher.run_async())
19 await asyncio.sleep(3600)
20 watcher.stop()
21 await watch_task
22
23asyncio.run(main())

Node.js Usage

watch.ts
typescript
1import { Watch } from 'crawlingo';
2
3const watcher = new Watch('https://example.com/product/1')
4 .field('title', 'h1')
5 .field('price', 'span.price', { extractionType: 'price' })
6 .interval(60);
7
8watcher.run((err, event) => {
9 if (err) return console.error(err);
10 console.log(`[${event.changeType}] ${event.field} changed!`);
11 console.log(` Old: ${event.oldValue}`);
12 console.log(` New: ${event.newValue}`);
13});

Parameters

MethodDefaultDescription
field(name, selector)Field to monitor for changes
interval(secs)300Polling interval in seconds
on_change(callback)Callback function invoked on change events
tolerance(pct)0.0Price change percentage tolerance (e.g. 0.05 = 5%)

Change Event Properties

PropertyTypeDescription
fieldstrName of the field that changed
old_valuestrBaseline extracted value
new_valuestrNewly extracted value
event_typestrContentChange, PriceChange, StockChange, ElementAdded, ElementRemoved