Documentation
¶
Overview ¶
Package htmlnode provides the HTML node implementation (Node-RED type ID "html" - named htmlnode here to avoid shadowing the imported golang.org/x/net/html package within this file).
HTML extracts content from an HTML string in msg.payload using a CSS selector and writes the result(s) to msg.payload.
Scope cut vs. Node-RED (which uses cheerio, a full CSS selector engine - see docs/NODE_PALETTE_PLAN.md): only a minimal selector subset is supported, parsed and matched by hand rather than via a new dependency:
- simple selectors: an optional tag name, an optional #id, and any number of .class selectors, e.g. "div.card#main"
- the descendant combinator (whitespace), e.g. "div.card p"
Not supported: child (>), sibling (+, ~) combinators, attribute selectors ([href]), pseudo-classes (:nth-child, :first-child, ...), or comma-separated selector lists.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// Selector is the (subset) CSS selector to match.
Selector string
// Ret is "html" (outer markup, the default), "text" (concatenated text
// content), or "attr" (the value of Attr).
Ret string
// Attr is the attribute name to extract when Ret is "attr".
Attr string
}
Node holds an HTML node's configuration.
func (*Node) Execute ¶
func (n *Node) Execute(ctx interface{}, input map[string]interface{}) (map[string]interface{}, error)
Execute parses input["payload"] as HTML and extracts every element matching Selector. A single match is written as a bare value; multiple matches (or zero) are written as an array.