Documentation
¶
Overview ¶
dom makes it easier to interact with the html document.
Node = return all the nodes Element = return all the nodes that are of type Element. This e.g. excludes #text nodes.
Index ¶
- func AllChildElements(node *html.Node) (children []*html.Node)
- func AllChildNodes(node *html.Node) (children []*html.Node)
- func AllNodes(startNode *html.Node) (allNodes []*html.Node)
- func CollectText(node *html.Node) string
- func ContainsNode(startNode *html.Node, matchFn func(node *html.Node) bool) bool
- func FindAllNodes(startNode *html.Node, matchFn func(node *html.Node) bool) (foundNodes []*html.Node)
- func FindFirstNode(startNode *html.Node, matchFn func(node *html.Node) bool) *html.Node
- func FirstChildElement(node *html.Node) *html.Node
- func FirstChildNode(node *html.Node) *html.Node
- func GetAttribute(node *html.Node, key string) (string, bool)
- func GetAttributeOr(node *html.Node, key string, fallback string) string
- func GetClasses(node *html.Node) []string
- func GetNextNeighborElement(node *html.Node) *html.Node
- func GetNextNeighborElementExcludingOwnChild(node *html.Node) *html.Node
- func GetNextNeighborNode(node *html.Node) *html.Node
- func GetNextNeighborNodeExcludingOwnChild(node *html.Node) *html.Node
- func GetPrevNeighborElement(node *html.Node) *html.Node
- func GetPrevNeighborElementExcludingOwnChild(node *html.Node) *html.Node
- func GetPrevNeighborNode(node *html.Node) *html.Node
- func GetPrevNeighborNodeExcludingOwnChild(node *html.Node) *html.Node
- func HasClass(node *html.Node, expectedClass string) bool
- func HasID(node *html.Node, expectedID string) bool
- func NameIsBlockNode(name string) bool
- func NameIsHeading(name string) bool
- func NameIsInlineNode(name string) bool
- func NextSiblingElement(node *html.Node) *html.Node
- func NextSiblingNode(node *html.Node) *html.Node
- func NodeName(node *html.Node) string
- func PrevSiblingElement(node *html.Node) *html.Node
- func PrevSiblingNode(node *html.Node) *html.Node
- func RemoveNode(node *html.Node)
- func RenderRepresentation(startNode *html.Node) string
- func ReplaceNode(node, newNode *html.Node)
- func UNSTABLE_initGetNeighbor(firstChildFunc func(node *html.Node) *html.Node, ...) func(*html.Node) *html.Node
- func UnwrapNode(node *html.Node)
- func WrapNode(existingNode, newNode *html.Node) *html.Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllChildElements ¶
AllChildElements is similar to AllChildNodes but only returns nodes of type `ElementNode`.
func CollectText ¶
func ContainsNode ¶
func FindAllNodes ¶
func FindFirstNode ¶
Example ¶
package main import ( "fmt" "log" "strings" "github.com/JohannesKaufmann/dom" "golang.org/x/net/html" ) func main() { input := ` <ul> <li><a href="github.com/JohannesKaufmann/dom">dom</a></li> <li><a href="github.com/JohannesKaufmann/html-to-markdown">html-to-markdown</a></li> </ul> ` doc, err := html.Parse(strings.NewReader(input)) if err != nil { log.Fatal(err) } // - - - // firstLink := dom.FindFirstNode(doc, func(node *html.Node) bool { return dom.NodeName(node) == "a" }) fmt.Println(dom.GetAttributeOr(firstLink, "href", "")) }
Output: github.com/JohannesKaufmann/dom
func GetClasses ¶
func NameIsBlockNode ¶
func NameIsHeading ¶
func NameIsInlineNode ¶
func NextSiblingElement ¶
NextSiblingElement returns the element immediately following the passed-in node or nil. In contrast to `node.NextSibling` this only returns the next `ElementNode`.
func NodeName ¶
In order to stay consistent with v1 of the library, this follows the naming scheme of goquery. E.g. "#text", "div", ...
func RemoveNode ¶
func RenderRepresentation ¶
RenderRepresentation is useful for debugging. It renders out the *structure* of the dom.
func ReplaceNode ¶
func UNSTABLE_initGetNeighbor ¶
func UNSTABLE_initGetNeighbor( firstChildFunc func(node *html.Node) *html.Node, prevNextFunc func(node *html.Node) *html.Node, goUpUntilFunc func(node *html.Node) bool, ) func(*html.Node) *html.Node
Warning: It is not meant to be called directly and may change signature from release to release!
func UnwrapNode ¶
Types ¶
This section is empty.