Docs/API reference

Watch · Python

Poll selected fields and deliver detected changes to application callbacks.

Download .md
Developers4 min read17 sections
Source reference · Match your SDK version. Availability and known issues
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 Watch
python1 lines · copy-ready

Usage 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()
python7 lines · copy-ready

Members

MemberKindReturn / value typeSource status
__init__methodNot annotated; see behavior notesPresent in source
fieldmethod'Watch'Present in source
intervalmethod'Watch'Present in source
auto_matchmethod'Watch'Present in source
on_changemethod'Watch'Present in source
on_price_changemethod'Watch'Present in source
on_stock_changemethod'Watch'Present in source
on_element_addedmethod'Watch'Present in source
on_element_removedmethod'Watch'Present in source
runmethodNot annotated; see behavior notesPresent in source
run_asyncmethodNot annotated; see behavior notesPresent in source
stopmethodNot annotated; see behavior notesPresent 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)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.
sessionOptional[Session]Default: NoneShared 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestrRequiredField, header or attribute name for this operation.
selectorstrRequiredSelector evaluated against the fetched DOM.
selector_typestrDefault: 'css'Selector engine for this field; supported values differ between builders.
transformOptional[Callable[[str], str]]Default: NonePython callback applied to the extracted string; application exceptions propagate.
defaultOptional[str]Default: NoneFallback 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsintRequiredTime 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledboolRequiredEnable or disable this behavior.

on_change()

Register a Python callback for change events.

Returns / value: 'Watch'.

def on_change(self, fn: Callable) -> 'Watch'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnCallableRequiredApplication 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnCallableRequiredApplication 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnCallableRequiredApplication 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnCallableRequiredApplication 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'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
fnCallableRequiredApplication 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)
python1 lines · copy-ready

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)
python1 lines · copy-ready

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)
python1 lines · copy-ready

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.