Documentation ¶
Index ¶
- func AppendChild(node *html.Node, child *html.Node)
- func ChildNodes(node *html.Node) []*html.Node
- func Children(node *html.Node) []*html.Node
- func ClassName(node *html.Node) string
- func Clone(src *html.Node, deep bool) *html.Node
- func CreateElement(tagName string) *html.Node
- func CreateTextNode(data string) *html.Node
- func DetachChild(child *html.Node)
- func DocumentElement(doc *html.Node) *html.Node
- func FastParse(r io.Reader) (*html.Node, error)
- func FirstElementChild(node *html.Node) *html.Node
- func ForEachNode(nodeList []*html.Node, fn func(*html.Node, int))
- func GetAllNodesWithTag(node *html.Node, tagNames ...string) []*html.Node
- func GetAttribute(node *html.Node, attrName string) string
- func GetElementByID(doc *html.Node, id string) *html.Node
- func GetElementsByClassName(doc *html.Node, classNames string) []*html.Node
- func GetElementsByTagName(doc *html.Node, tagName string) []*html.Node
- func HasAttribute(node *html.Node, attrName string) bool
- func ID(node *html.Node) string
- func IncludeNode(nodeList []*html.Node, node *html.Node) bool
- func InnerHTML(node *html.Node) string
- func InnerText(node *html.Node) string
- func IsVoidElement(n *html.Node) bool
- func NextElementSibling(node *html.Node) *html.Node
- func OuterHTML(node *html.Node) string
- func Parse(r io.Reader) (*html.Node, error)
- func PrependChild(node *html.Node, child *html.Node)
- func PreviousElementSibling(node *html.Node) *html.Node
- func QuerySelector(doc *html.Node, selectors string) *html.Node
- func QuerySelectorAll(doc *html.Node, selectors string) []*html.Node
- func RemoveAttribute(node *html.Node, attrName string)
- func RemoveNodes(nodeList []*html.Node, filterFn func(*html.Node) bool)
- func ReplaceChild(parent *html.Node, newChild *html.Node, oldChild *html.Node) (*html.Node, *html.Node)
- func SetAttribute(node *html.Node, attrName string, attrValue string)
- func SetInnerHTML(node *html.Node, rawHTML string)
- func SetTextContent(node *html.Node, text string)
- func TagName(node *html.Node) string
- func TextContent(node *html.Node) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendChild ¶
AppendChild adds a node to the end of the list of children of a specified parent node. If the given child is a reference to an existing node in the document, AppendChild() moves it from its current position to the new position.
func ChildNodes ¶
ChildNodes returns list of a node's direct children.
func Clone ¶
Clone returns a clone of the node and (if specified) its children. However, it will be detached from the original's parents and siblings.
func CreateElement ¶
CreateElement creates a new ElementNode with specified tag.
func CreateTextNode ¶
CreateTextNode creates a new Text node.
func DetachChild ¶
func DocumentElement ¶
DocumentElement returns the Element that is the root element of the document. Since we are working with HTML document, the root will be <html> element for HTML documents).
func FastParse ¶
FastParse parses html.Node from the specified reader without caring about text encoding. It always assume that the input uses UTF-8 encoding.
func FirstElementChild ¶
FirstElementChild returns the object's first child Element, or nil if there are no child elements.
func ForEachNode ¶
ForEachNode iterates over a NodeList and runs fn on each node.
func GetAllNodesWithTag ¶
GetAllNodesWithTag is wrapper for GetElementsByTagName() which allow to get several tags at once.
func GetAttribute ¶
GetAttribute returns the value of a specified attribute on the element. If the given attribute does not exist, the value returned will be an empty string.
func GetElementByID ¶
GetElementByID returns a Node object representing the element whose id property matches the specified string.
func GetElementsByClassName ¶
GetElementsByClassName returns an array of all child elements which have all of the given class name(s).
func GetElementsByTagName ¶
GetElementsByTagName returns a collection of all elements in the document with the specified tag name, as an array of Node object. The special tag "*" will represents all elements.
func HasAttribute ¶
HasAttribute returns a Boolean value indicating whether the specified node has the specified attribute or not.
func IncludeNode ¶
IncludeNode determines if node is included inside nodeList.
func InnerHTML ¶
InnerHTML returns the HTML content (inner HTML) of an element. The returned HTML value is escaped.
func InnerText ¶
InnerText in JS used to capture text from an element while excluding text from hidden children. A child is hidden if it's computed width is 0, whether because its CSS (e.g `display: none`, `visibility: hidden`, etc), or if the child has `hidden` attribute. Since we can't compute stylesheet, we only look at `hidden` attribute and inline style.
Besides excluding text from hidden children, difference between this function and `TextContent` is the latter will skip <br> tag while this function will preserve <br> as newline.
func IsVoidElement ¶
IsVoidElement check whether a node can have any contents or not. Return true if element is void (can't have any children).
func NextElementSibling ¶
NextElementSibling returns the Element immediately following the specified one in its parent's children list, or nil if the specified Element is the last one in the list.
func OuterHTML ¶
OuterHTML returns an HTML serialization of the element and its descendants. The returned HTML value is escaped.
func Parse ¶
Parse parses html.Node from the specified reader while converting the character encoding into UTF-8. This function is useful to correctly parse web pages that uses custom text encoding, e.g. web pages from Asian websites. However, since it has to detect charset before parsing, this function is quite slow and expensive so if you sure the reader uses valid UTF-8, just use FastParse.
func PrependChild ¶
PrependChild works like AppendChild() except it adds a node to the beginning of the list of children of a specified parent node.
func PreviousElementSibling ¶
PreviousElementSibling returns the the Element immediately prior to the specified one in its parent's children list, or null if the specified element is the first one in the list.
func QuerySelector ¶
QuerySelector returns the first document's element that match the specified group of selectors.
func QuerySelectorAll ¶
QuerySelectorAll returns array of document's elements that match the specified group of selectors.
func RemoveAttribute ¶
RemoveAttribute removes attribute with given name.
func RemoveNodes ¶
RemoveNodes iterates over a NodeList, calls `filterFn` for each node and removes node if function returned `true`. If function is not passed, removes all the nodes in node list.
func ReplaceChild ¶
func ReplaceChild(parent *html.Node, newChild *html.Node, oldChild *html.Node) (*html.Node, *html.Node)
ReplaceChild replaces a child node within the given (parent) node. If the new child is already exist in document, ReplaceChild() will move it from its current position to replace old child. Returns both the new and old child.
TODO: I'm note sure but I *think* there are some issues here. Check later I guess.
func SetAttribute ¶
SetAttribute sets attribute for node. If attribute already exists, it will be replaced.
func SetInnerHTML ¶
SetInnerHTML sets inner HTML of the specified node.
func SetTextContent ¶
SetTextContent sets the text content of the specified node.
func TagName ¶
TagName returns the tag name of a Node. If it's not ElementNode, return empty string.
func TextContent ¶
TextContent returns the text content of the specified node, and all its descendants.
Types ¶
This section is empty.