Documentation ¶
Overview ¶
Package scrape provides a searching api on top of golang.org/x/net/html
Index ¶
- func Attr(node *html.Node, key string) string
- func Find(node *html.Node, matcher Matcher) (n *html.Node, ok bool)
- func FindAll(node *html.Node, matcher Matcher) []*html.Node
- func FindAllNested(node *html.Node, matcher Matcher) []*html.Node
- func FindNextSibling(node *html.Node, matcher Matcher) (n *html.Node, ok bool)
- func FindParent(node *html.Node, matcher Matcher) (n *html.Node, ok bool)
- func FindPrevSibling(node *html.Node, matcher Matcher) (n *html.Node, ok bool)
- func Text(node *html.Node) string
- func TextJoin(node *html.Node, join func([]string) string) string
- type Matcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶
Find returns the first node which matches the matcher using depth-first search. If no node is found, ok will be false.
root, err := html.Parse(resp.Body) if err != nil { // handle error } matcher := func(n *html.Node) bool { return n.DataAtom == atom.Body } body, ok := scrape.Find(root, matcher)
func FindAll ¶
FindAll returns all nodes which match the provided Matcher. After discovering a matching node, it will _not_ discover matching subnodes of that node.
func FindAllNested ¶
FindAllNested returns all nodes which match the provided Matcher and _will_ discover matching subnodes of matching nodes.
func FindNextSibling ¶
Find returns the first node which matches the matcher using next sibling search. If no node is found, ok will be false.
root, err := html.Parse(resp.Body) if err != nil { // handle error } matcher := func(n *html.Node) bool { return n.DataAtom == atom.Body } body, ok := scrape.FindNextSibling(root, matcher)
func FindParent ¶
FindParent searches up HTML tree from the current node until either a match is found or the top is hit.
func FindPrevSibling ¶
Find returns the first node which matches the matcher using previous sibling search. If no node is found, ok will be false.
root, err := html.Parse(resp.Body) if err != nil { // handle error } matcher := func(n *html.Node) bool { return n.DataAtom == atom.Body } body, ok := scrape.FindPrevSibling(root, matcher)