pyrtan / sourcev0.13.0 · main

pyrtan / examples / rendered-headline / rendered-headline.toml

1,708 bytes · last changed 2026-10-26 in The catalog grows up: namespaces, publishing by pull request through the gate, gap reports gossiped back to authors; release 0.8.0

1# The main heading of a page that needs a script to render: a browser node
2# opens it in a real browser (Playwright's Chromium, the one optional
3# dependency: pip install 'pyrtan[browser]'), waits for a selector, and
4# hands the rendered document to the same extraction an http node uses.
5# The page may fetch what it likes; it may not take the tree to a host
6# outside `hosts`.
7
8name = "rendered-headline"
9version = 2
10namespace = "pyrtan"
11description = "The main heading of a page that needs a script to render, through a real browser."
12tags = ["web", "browser", "read-only"]
13license = "MIT"
14hosts = ["*"]
15start = "open"
16
17[[triggers]]
18pattern = "headline of {url:url}"
19[[triggers]]
20pattern = "what does {url:url} say"
21
22[inputs.url]
23type = "str"
24pattern = "^https?://.+$"
25
26[nodes.open]
27kind = "observe"
28browser = { url = "{{ inputs.url }}", wait_for = "h1" }
29into = "page" # state.page = { url, status, ok, title, body, elapsed_ms }
30timeout = 30
31retries = 0
32extract = [{ into = "heading", css = "h1" }]
33next = "loaded"
34
35[nodes.loaded]
36kind = "decide"
37on = "page.ok"
38branches = [{ when = { eq = true }, then = "found" }, { else = "not-ok" }]
39
40[nodes.found]
41kind = "decide"
42on = "heading"
43branches = [{ when = { exists = true }, then = "say" }, { else = "none" }]
44
45[nodes.say]
46kind = "done"
47say = "{{ state.page.title }} — {{ state.heading | strip }}"
48output = { url = "{{ state.page.url }}", title = "{{ state.page.title }}", heading = "{{ state.heading | strip }}" }
49
50[nodes.none]
51kind = "fail"
52reason = "no-heading"
53say = "{{ state.page.url }} rendered without an h1."
54
55[nodes.not-ok]
56kind = "fail"
57reason = "unexpected-response"
58say = "{{ inputs.url }} answered {{ state.page.status }}."