Documentation ¶
Index ¶
- func Apply(n *html.Node, predicates [][]Predicate) []*html.Node
- func ExtractChildText(n *html.Node) string
- func ExtractChildrenTexts(n *html.Node) string
- func MatchAll(n *html.Node, predicates []Predicate) bool
- func Squeeze(n *html.Node, predicates [][]Predicate, extract Extractor) []string
- func SqueezeSelector(n *html.Node, selectors string, extract Extractor) []string
- func TagClassMatchers(selectors []string) [][]Predicate
- func TagClassMatchersOf(selectors string) [][]Predicate
- type Extractor
- type Predicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply applies the given predicates to the given node, and returns the matching nodes. If a node satisfies all the predicates of the first sub-list, the remaining predicates are applied to the node's children; otherwise all the predicates are applied to the node's children. If no more predicates are left to be satisfied, the node is considered a match and returned.
func ExtractChildText ¶
ExtractChildText returns the text of n's first child, if it is a text node, and the empty string otherwise.
func ExtractChildrenTexts ¶ added in v0.0.4
ExtractChildrenTexts returns the text of n's children that are text nodes separated by space.
func MatchAll ¶
MatchAll applies the given predicates to a node, returns true if the node satisfies all those predicates, and false otherwise.
func Squeeze ¶
Squeeze applies the given predicates to the given node, applies the given extractor to the matching nodes, and returns the extracted text as a list of strings.
func SqueezeSelector ¶ added in v0.0.3
SqueezeSelector is a convenience interface for Squeeze, which produces the predicates using the given selectors by invoking TagClassMatchersOf.
func TagClassMatchers ¶ added in v0.0.3
TagClassMatchers expects multiple selectors. For each selector, TagClassMatcher is invoked to produce a list of predicates. Those predicates are returned as a list of predicate lists, which can be used for the Squeeze and Apply functions.
func TagClassMatchersOf ¶ added in v0.0.3
TagClassMatchersOf expects multiple selectors encoded in a single string, such as "div.main p.text", which are split into fields, and given as a parameter to TagClassMatchers to produce the specified predicates.
Types ¶
type Predicate ¶
Predicate returns true if the given node satisfies a condition, and false otherwise.
func ClassMatcher ¶
ClassMatcher creates a predicate that tests if a node has a class attribute containing the given name.
func DontMatch ¶ added in v0.0.3
func DontMatch() Predicate
DontMatch is a dummy matcher that never matches.
func TagClassMatcher ¶ added in v0.0.3
TagClassMatcher expects a selector like "div.main" (matching div elements with class main) or "div" (just matching div elements) and produces a list of according predicates. If the selector is malformed, a predicate list containing DontMatch is returned, which matches to nothing.
func TagMatcher ¶
TagMatcher creates a predicate that tests if a node is an element node of the given name.