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 | |
| 8 | name = "rendered-headline" |
| 9 | version = 2 |
| 10 | namespace = "pyrtan" |
| 11 | description = "The main heading of a page that needs a script to render, through a real browser." |
| 12 | tags = ["web", "browser", "read-only"] |
| 13 | license = "MIT" |
| 14 | hosts = ["*"] |
| 15 | start = "open" |
| 16 | |
| 17 | [[triggers]] |
| 18 | pattern = "headline of {url:url}" |
| 19 | [[triggers]] |
| 20 | pattern = "what does {url:url} say" |
| 21 | |
| 22 | [inputs.url] |
| 23 | type = "str" |
| 24 | pattern = "^https?://.+$" |
| 25 | |
| 26 | [nodes.open] |
| 27 | kind = "observe" |
| 28 | browser = { url = "{{ inputs.url }}", wait_for = "h1" } |
| 29 | into = "page" # state.page = { url, status, ok, title, body, elapsed_ms } |
| 30 | timeout = 30 |
| 31 | retries = 0 |
| 32 | extract = [{ into = "heading", css = "h1" }] |
| 33 | next = "loaded" |
| 34 | |
| 35 | [nodes.loaded] |
| 36 | kind = "decide" |
| 37 | on = "page.ok" |
| 38 | branches = [{ when = { eq = true }, then = "found" }, { else = "not-ok" }] |
| 39 | |
| 40 | [nodes.found] |
| 41 | kind = "decide" |
| 42 | on = "heading" |
| 43 | branches = [{ when = { exists = true }, then = "say" }, { else = "none" }] |
| 44 | |
| 45 | [nodes.say] |
| 46 | kind = "done" |
| 47 | say = "{{ state.page.title }} — {{ state.heading | strip }}" |
| 48 | output = { url = "{{ state.page.url }}", title = "{{ state.page.title }}", heading = "{{ state.heading | strip }}" } |
| 49 | |
| 50 | [nodes.none] |
| 51 | kind = "fail" |
| 52 | reason = "no-heading" |
| 53 | say = "{{ state.page.url }} rendered without an h1." |
| 54 | |
| 55 | [nodes.not-ok] |
| 56 | kind = "fail" |
| 57 | reason = "unexpected-response" |
| 58 | say = "{{ inputs.url }} answered {{ state.page.status }}." |