Watch · Python
Poll selected fields and deliver detected changes to application callbacks.
In this guide
Purpose and lifecycle
The first successful sample establishes a baseline; later samples are compared with it. Stop the watcher explicitly when the worker shuts down.
Node run takes an error-first callback. Python registers callbacks with on_change and typed event helpers; run blocks and run_async uses an executor.
Set a positive interval in whole seconds. Zero is not a supported polling interval. Callback delivery and baseline state are not a durable event log.
Definition and availability
Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.
Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.
class WatchUsage example
Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.
from crawlingo import Watch
watch = Watch("https://example.com/").field("title", "h1").interval(60)
watch.on_change(lambda event: print(event.field, event.old_value, event.new_value))
try:
watch.run()
finally:
watch.stop()Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| __init__ | method | Not annotated; see behavior notes | Present in source |
| field | method | 'Watch' | Present in source |
| interval | method | 'Watch' | Present in source |
| auto_match | method | 'Watch' | Present in source |
| on_change | method | 'Watch' | Present in source |
| on_price_change | method | 'Watch' | Present in source |
| on_stock_change | method | 'Watch' | Present in source |
| on_element_added | method | 'Watch' | Present in source |
| on_element_removed | method | 'Watch' | Present in source |
| run | method | Not annotated; see behavior notes | Present in source |
| run_async | method | Not annotated; see behavior notes | Present in source |
| stop | method | Not annotated; see behavior notes | Present in source |
__init__()
Create a monitor with a URL and optional session. Add fields and callbacks before starting the polling loop with run.
Returns / value: Not annotated; see behavior notes.
def __init__(self, url: str, session: Optional[Session]=None)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | str | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
| session | Optional[Session] | Default: None | Shared request state. Omit only where the signature provides a default. |
field()
Add a named field to compare between polls. Configure all fields before starting.
Returns / value: 'Watch'.
def field(self, name: str, selector: str, selector_type: str='css', transform: Optional[Callable[[str], str]]=None, default: Optional[str]=None) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| name | str | Required | Field, header or attribute name for this operation. |
| selector | str | Required | Selector evaluated against the fetched DOM. |
| selector_type | str | Default: 'css' | Selector engine for this field; supported values differ between builders. |
| transform | Optional[Callable[[str], str]] | Default: None | Python callback applied to the extracted string; application exceptions propagate. |
| default | Optional[str] | Default: None | Fallback field value when extraction is empty. |
interval()
Set a positive poll interval in seconds. This is not a request timeout.
Returns / value: 'Watch'.
def interval(self, seconds: int) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| seconds | int | Required | Time in seconds; see the method-specific range and timing semantics. |
auto_match()
Enable heuristic Dataset selector recovery on the shared session.
Returns / value: 'Watch'.
def auto_match(self, enabled: bool) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| enabled | bool | Required | Enable or disable this behavior. |
on_change()
Register a Python callback for change events.
Returns / value: 'Watch'.
def on_change(self, fn: Callable) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Callable | Required | Application callback invoked with the documented value or event. |
on_price_change()
Register a callback for detected price changes.
Returns / value: 'Watch'.
def on_price_change(self, fn: Callable) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Callable | Required | Application callback invoked with the documented value or event. |
on_stock_change()
Register a callback for stock status changes.
Returns / value: 'Watch'.
def on_stock_change(self, fn: Callable) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Callable | Required | Application callback invoked with the documented value or event. |
on_element_added()
Register a callback for added-element events.
Returns / value: 'Watch'.
def on_element_added(self, fn: Callable) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Callable | Required | Application callback invoked with the documented value or event. |
on_element_removed()
Register a callback for removed-element events.
Returns / value: 'Watch'.
def on_element_removed(self, fn: Callable) -> 'Watch'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| fn | Callable | Required | Application callback invoked with the documented value or event. |
run()
Start polling. Node returns immediately and delivers callbacks; Python blocks.
Returns / value: Not annotated; see behavior notes.
def run(self)run_async()
Run the blocking Python poll loop in an executor. Cancellation of the asyncio task alone is not a substitute for stop().
Returns / value: Not annotated; see behavior notes.
async def run_async(self)stop()
Request cancellation of the polling loop. It does not erase a separately owned dataset directory.
Returns / value: Not annotated; see behavior notes.
def stop(self)Errors and operational limits
Node reports poll failures to the callback. Handle err before reading the event. Python native polling logs some failures; it is not equivalent to a rejected DatasetJob.
Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.