html

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XGoPackage = true
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	html.Node
}

File represents an HTML file.

func Parse

func Parse(r io.Reader) (f *File, err error)

Parse returns the parse tree for the HTML from the given Reader.

func (*File) Dump

func (f *File) Dump() NodeSet

Dump prints the node for debugging purposes.

func (*File) XGo_Any

func (f *File) XGo_Any(name string) NodeSet

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 (*File) XGo_Child

func (f *File) XGo_Child() NodeSet

XGo_Child returns a NodeSet containing all child nodes of the node.

  • .*

func (*File) XGo_Elem

func (f *File) XGo_Elem(name string) NodeSet

XGo_Elem returns a NodeSet containing the child nodes with the specified name.

  • .name
  • .“element-name”

type Node

type Node = html.Node

Node represents an HTML node.

type NodeSet

type NodeSet struct {
	Data iter.Seq[*Node]
	Err  error
}

NodeSet represents a set of HTML nodes.

func New

func New(r io.Reader) NodeSet

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

func NodeSet_Cast(seq iter.Seq[*Node]) NodeSet

NodeSet(seq) casts a NodeSet from a sequence of nodes.

func Nodes

func Nodes(nodes ...*Node) NodeSet

Nodes creates a NodeSet containing the provided nodes.

func Root

func Root(doc *Node) NodeSet

Root creates a NodeSet containing the provided root node.

func Source

func Source(r any) (ret NodeSet)

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

func (p NodeSet) All() NodeSet

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) Collect

func (p NodeSet) Collect() ([]*Node, error)

Collect retrieves all nodes from the NodeSet.

func (NodeSet) Dump

func (p NodeSet) Dump() NodeSet

Dump prints the nodes in the NodeSet for debugging purposes.

func (NodeSet) First

func (p NodeSet) First() (*Node, error)

First returns the first node in the NodeSet.

func (NodeSet) FirstElementChild

func (p NodeSet) FirstElementChild() NodeSet

FirstElementChild returns a NodeSet containing the first element child of each node.

func (NodeSet) HasAttr

func (p NodeSet) HasAttr(name string) bool

HasAttr returns true if the first node in the NodeSet has the specified attribute. It returns false otherwise.

func (NodeSet) Int

func (p NodeSet) Int() (int, error)

Int retrieves the integer value from the text content of the first node in the NodeSet.

func (NodeSet) NextSibling

func (p NodeSet) NextSibling() NodeSet

NextSibling returns a NodeSet containing the next sibling nodes.

func (NodeSet) Ok added in v1.6.5

func (p NodeSet) Ok() bool

Ok returns true if there is no error in the NodeSet.

func (NodeSet) One

func (p NodeSet) One() NodeSet

One returns a NodeSet containing the first node. It's a performance optimization when you only need the first node (stop early).

func (NodeSet) Parent

func (p NodeSet) Parent() NodeSet

Parent returns a NodeSet containing the parent nodes.

func (NodeSet) ParentN

func (p NodeSet) ParentN(n int) NodeSet

ParentN returns a NodeSet containing the N-th parent nodes.

func (NodeSet) PrevSibling

func (p NodeSet) PrevSibling() NodeSet

PrevSibling returns a NodeSet containing the previous sibling nodes.

func (NodeSet) Single

func (p NodeSet) Single() NodeSet

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) TextNode

func (p NodeSet) TextNode() NodeSet

TextNode returns a NodeSet containing all text nodes.

func (NodeSet) Text__0

func (p NodeSet) Text__0() string

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

func (p NodeSet) Text__1() (val string, err error)

Text retrieves the text content of the NodeSet. It only retrieves from the first node in the NodeSet.

func (NodeSet) Value__0

func (p NodeSet) Value__0() string

Value returns the data content of the first node in the NodeSet.

func (NodeSet) Value__1

func (p NodeSet) Value__1() (val string, err error)

Value returns the data content of the first node in the NodeSet.

func (NodeSet) XGo_Any

func (p NodeSet) XGo_Any(name string) NodeSet

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

func (p NodeSet) XGo_Attr__0(name string) string

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

func (p NodeSet) XGo_Attr__1(name string) (val string, err error)

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

func (p NodeSet) XGo_Child() NodeSet

XGo_Child returns a NodeSet containing all child nodes of the nodes in the NodeSet.

func (NodeSet) XGo_Elem

func (p NodeSet) XGo_Elem(name string) NodeSet

XGo_Elem returns a NodeSet containing the child nodes with the specified name.

  • .name
  • .“element-name”

func (NodeSet) XGo_Enum

func (p NodeSet) XGo_Enum() iter.Seq[NodeSet]

XGo_Enum returns an iterator over the nodes in the NodeSet.

func (NodeSet) XGo_Select

func (p NodeSet) XGo_Select(name string) NodeSet

XGo_Select returns a NodeSet containing the nodes with the specified name.

  • @name
  • @"element-name"

func (NodeSet) XGo_first

func (p NodeSet) XGo_first() (ret *Node, err error)

_first returns the first node in the NodeSet. It's required by XGo compiler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL