A Selector is a function which tells whether a node matches or not.
This type is maintained for compatibility; I recommend using the newer and
more idiomatic interfaces Sel and Matcher.
Filter returns the nodes in nodes that match the selector.
Match returns true if the node matches the selector.
MatchAll returns a slice of the nodes that match the selector,
from n and its children.
MatchFirst returns the first node that matches s, from n and its children.
( T) matchAllInto(n *html.Node, storage []*html.Node) []*html.Node
T : Matcher
func Compile(sel string) (Selector, error)
func MustCompile(sel string) Selector
A SelectorGroup is a list of selectors, which matches if any of the
individual selectors matches.
Match returns true if the node matches one of the single selectors.
T : Matcher
func ParseGroup(sel string) (SelectorGroup, error)
Specificity is the CSS specificity as defined in
https://www.w3.org/TR/selectors/#specificity-rules
with the convention Specificity = [A,B,C].
( T) Add(other Specificity) Specificity
returns `true` if s < other (strictly), false otherwise
func Sel.Specificity() Specificity
func Specificity.Add(other Specificity) Specificity
func Specificity.Add(other Specificity) Specificity
func Specificity.Less(other Specificity) bool
a parser for CSS selectors
// the current position
// the source text
consumeClosingParenthesis consumes a closing parenthesis and any preceding
whitespace. It returns true if there was actually a parenthesis to skip.
consumeParenthesis consumes an opening parenthesis and any following
whitespace. It returns true if there was actually a parenthesis to skip.
parseAttributeSelector parses a selector that matches by attribute value.
parseClassSelector parses a selector that matches by class attribute.
parseEscape parses a backslash escape.
parseIDSelector parses a selector that matches by id attribute.
parseIdentifier parses an identifier.
parseInteger parses a decimal integer.
parseName parses a name (which is like an identifier, but doesn't have
extra restrictions on the first character).
parseNth parses the argument for :nth-child (normally of the form an+b).
parsePseudoclassSelector parses a pseudoclass selector like :not(p)
parseRegex parses a regular expression; the end is defined by encountering an
unmatched closing ')' or ']' which is not consumed
parseSelector parses a selector that may include combinators.
parseSelectorGroup parses a group of selectors, separated by commas.
parseSimpleSelectorSequence parses a selector sequence that applies to
a single element.
parseString parses a single- or double-quoted string.
parseTypeSelector parses a type selector (one that matches by tag name).
skipWhitespace consumes whitespace characters and comments.
It returns true if there was actually anything to skip.
matchSelectorGroup
// one of "not", "has", "haschild"
( T) Match(n *html.Node) bool
Specificity returns the specificity of the most specific selectors
in the pseudo-class arguments.
See https://www.w3.org/TR/selectors/#specificity-rules
T : Matcher
T : Sel
Package-Level Functions (total 31, in which 7 are exported)
Compile parses a selector and returns, if successful, a Selector object
that can be used to match against html.Node objects.
Filter returns the nodes that match m.
MustCompile is like Compile, but panics instead of returning an error.
Parse parses a selector.
ParseGroup parses a selector, or a group of selectors separated by commas.
Query returns the first node that matches m, from the descendants of n.
If none matches, it returns nil.
QueryAll returns a slice of all the nodes that match m, from the descendants
of n.
matches elements where the attribute named key equals val or starts with val plus a hyphen.
attributeNotEqualMatch matches elements where
the attribute named key does not have the value val.
attributePrefixMatch returns a Selector that matches elements where
the attribute named key starts with val.
attributeRegexMatch matches nodes where
the attribute named key matches the regular expression rx
attributeSubstringMatch matches nodes where
the attribute named key contains val.
attributeSuffixMatch matches elements where
the attribute named key ends with val.
matches an element if it matches d and its parent matches a.
matches an element if it matches d and has an ancestor that matches a.
hasChildMatch returns whether n has any child that matches a.
hasDescendantMatch performs a depth-first search of n's descendants,
testing whether any of them match a. It returns true as soon as a match is
found, or false if no match is found.
matches an element if it matches s2 and is preceded by an element that matches s1.
If adjacent is true, the sibling must be immediately before the element.
simpleNthChildMatch implements :nth-child(b).
If ofType is true, implements :nth-of-type instead.
simpleNthLastChildMatch implements :nth-last-child(b).
If ofType is true, implements :nth-last-of-type instead.
toLowerASCII returns s with all ASCII capital letters lowercased.
writeNodeText writes the text contained in n and its descendants to b.
Package-Level Variables (total 3, none are exported)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.