Documentation
¶
Index ¶
- Constants
- func ClassContains(classAttr, classVal string) bool
- func Text[F NodeFilter](ns NodeSet, outer bool, f F) (val string, err error)
- type Node
- func (n *Node) Dump() NodeSet
- func (n *Node) HasAttr(name string) bool
- func (n *Node) HasClass(val string) bool
- func (n *Node) IsClass(val string) bool
- func (n *Node) Name() string
- func (n *Node) Value() string
- func (n *Node) XGo_Any(name string) NodeSet
- func (n *Node) XGo_Attr__0(name string) string
- func (n *Node) XGo_Attr__1(name string) (string, error)
- func (n *Node) XGo_Child() NodeSet
- func (n *Node) XGo_Elem(name string) NodeSet
- type NodeFilter
- type NodeSet
- func (p NodeSet) All() NodeSet
- func (p NodeSet) Collect() ([]*Node, error)
- func (p NodeSet) Dump() NodeSet
- func (p NodeSet) First() (*Node, error)
- func (p NodeSet) FirstElementChild() NodeSet
- func (p NodeSet) HasAttr(name string) bool
- func (p NodeSet) HasClass(val string) bool
- func (p NodeSet) Int() (int, error)
- func (p NodeSet) IsClass(val string) bool
- func (p NodeSet) Name() string
- func (p NodeSet) NextSibling() NodeSet
- func (p NodeSet) Ok() bool
- func (p NodeSet) One() NodeSet
- func (p NodeSet) Parent() NodeSet
- func (p NodeSet) ParentN(n int) NodeSet
- func (p NodeSet) PrevSibling() NodeSet
- func (p NodeSet) Single() NodeSet
- func (p NodeSet) TextNode() NodeSet
- func (p NodeSet) Text__0() string
- func (p NodeSet) Text__1() (val string, err error)
- func (p NodeSet) Value__0() string
- func (p NodeSet) Value__1() (val string, err error)
- func (p NodeSet) XGo_Any(name string) NodeSet
- func (p NodeSet) XGo_Attr__0(name string) string
- func (p NodeSet) XGo_Attr__1(name string) (val string, err error)
- func (p NodeSet) XGo_Child() NodeSet
- func (p NodeSet) XGo_Elem(name string) NodeSet
- func (p NodeSet) XGo_Enum() iter.Seq[NodeSet]
- func (p NodeSet) XGo_Select(name string) NodeSet
- func (p NodeSet) XGo_first() (ret *Node, err error)
Constants ¶
const (
XGoPackage = true
)
Variables ¶
This section is empty.
Functions ¶
func ClassContains ¶ added in v1.7.0
ClassContains checks if the classVal is present in the classAttr string, which is a space-separated list of class names.
func Text ¶ added in v1.6.7
func Text[F NodeFilter](ns NodeSet, outer bool, f F) (val string, err error)
Text retrieves the text content of the NodeSet with a node filter. It only retrieves from the first node in the NodeSet.
The node filter is used to filter the nodes when retrieving text content. If the node filter returns false for a node, the node and its children will be ignored when retrieving text content.
The outer parameter specifies whether to include the text content of the outer node itself. If outer is true, the text content of the outer node will be included; otherwise, only the text content of the inner nodes will be included.
Types ¶
type Node ¶
Node represents an HTML node.
func (*Node) HasAttr ¶ added in v1.6.6
HasAttr returns true if the node has the specified attribute.
func (*Node) HasClass ¶ added in v1.7.0
HasClass returns true if the node has the specified class in its "class" attribute.
func (*Node) IsClass ¶ added in v1.7.0
IsClass returns true if the node's "class" attribute is exactly equal to the specified value.
func (*Node) Name ¶ added in v1.6.6
Name returns the name of the node if it's an element node, or an empty string otherwise.
func (*Node) XGo_Any ¶ added in v1.6.6
XGo_Any returns a NodeSet containing all descendant nodes (including the node itself) with the specified name. If name is "", it returns all nodes.
- .**.name
- .**.“element-name”
- .**.*
func (*Node) XGo_Attr__0 ¶ added in v1.6.6
XGo_Attr returns the value of the specified attribute from the node. If the attribute is not found, it returns an empty string.
- $name
- $“attr-name”
func (*Node) XGo_Attr__1 ¶ added in v1.6.6
XGo_Attr returns the value of the specified attribute from the node. If the attribute is not found, it returns ErrNotFound.
- $name
- $“attr-name”
type NodeFilter ¶ added in v1.6.7
type NodeFilter interface {
// Filter returns true if the node should be included in the text content.
Filter(*html.Node) bool
// TextNodeData returns the text data of a text node. It can be used to customize
// the text data of a text node, for example, to trim spaces or to replace certain
// characters.
TextNodeData(*html.Node) string
}
NodeFilter is the interface for filtering nodes when retrieving text content.
type NodeSet ¶
NodeSet represents a set of HTML nodes.
func New ¶
New parses the HTML document from the provided reader and returns a NodeSet containing the root node. If there is an error during parsing, the NodeSet's Err field is set.
func NodeSet_Cast ¶
NodeSet(seq) casts a NodeSet from a sequence of nodes.
func Source ¶
Source creates a NodeSet from various types of sources: - string: treated as an URL to read HTML content from. - []byte: treated as raw HTML content. - io.Reader: reads HTML content from the reader. - *Node: creates a NodeSet containing the single provided node. - iter.Seq[*Node]: directly uses the provided sequence of nodes. - NodeSet: returns the provided NodeSet as is. If the source type is unsupported, it panics.
func (NodeSet) All ¶
All returns a NodeSet containing all nodes. It's a cache operation for performance optimization when you need to traverse the nodes multiple times.
func (NodeSet) FirstElementChild ¶
FirstElementChild returns a NodeSet containing the first element child of each node.
func (NodeSet) HasAttr ¶
HasAttr returns true if the first node in the NodeSet has the specified attribute. It returns false otherwise.
func (NodeSet) HasClass ¶ added in v1.7.0
HasClass returns true if the first node in the NodeSet has the specified class in its "class" attribute.
func (NodeSet) Int ¶
Int retrieves the integer value from the text content of the first node in the NodeSet.
func (NodeSet) IsClass ¶ added in v1.7.0
IsClass returns true if the "class" attribute of the first node in the NodeSet is exactly equal to the specified value.
func (NodeSet) Name ¶ added in v1.6.6
Name returns the name of the first node in the NodeSet. empty string is returned if the NodeSet is empty or the first node is not an element node.
func (NodeSet) NextSibling ¶
NextSibling returns a NodeSet containing the next sibling nodes.
func (NodeSet) One ¶
One returns a NodeSet containing the first node. It's a performance optimization when you only need the first node (stop early).
func (NodeSet) PrevSibling ¶
PrevSibling returns a NodeSet containing the previous sibling nodes.
func (NodeSet) Single ¶
Single returns a NodeSet containing the single node. If there are zero or more than one nodes, it returns an error. ErrNotFound or ErrMultiEntities is returned accordingly.
func (NodeSet) Text__0 ¶
Text retrieves the text content of the NodeSet. It only retrieves from the first node in the NodeSet. It ignores any error and returns an empty string if there is an error.
func (NodeSet) Text__1 ¶
Text retrieves the text content of the NodeSet. It only retrieves from the first node in the NodeSet.
func (NodeSet) XGo_Any ¶
XGo_Any returns a NodeSet containing all descendant nodes (including the nodes themselves) with the specified name. If name is "textNode", it returns all text nodes. If name is "", it returns all nodes.
- .**.name
- .**.“element-name”
- .**.*
func (NodeSet) XGo_Attr__0 ¶
XGo_Attr returns the value of the specified attribute from the first node in the NodeSet. It only retrieves the attribute from the first node.
- $name
- $“attr-name”
func (NodeSet) XGo_Attr__1 ¶
XGo_Attr returns the value of the specified attribute from the first node in the NodeSet. It only retrieves the attribute from the first node.
- $name
- $“attr-name”
func (NodeSet) XGo_Child ¶
XGo_Child returns a NodeSet containing all child nodes of the nodes in the NodeSet.
func (NodeSet) XGo_Elem ¶
XGo_Elem returns a NodeSet containing the child nodes with the specified name.
- .name
- .“element-name”
func (NodeSet) XGo_Select ¶
XGo_Select returns a NodeSet containing the nodes with the specified name.
- @name
- @"element-name"