Documentation ¶
Overview ¶
Package supersimplesoup implements a super simple soup like DOM API.
Index ¶
- Variables
- func Walk(root *Node, fn WalkFunc) error
- type Node
- func (n *Node) Attribute(key string) string
- func (n *Node) Attributes() map[string]string
- func (n *Node) ChildrenNodes() (children []*Node)
- func (n *Node) Class() string
- func (n *Node) Find(tag string, attrkv ...string) (*Node, error)
- func (n *Node) FirstChildNode() *Node
- func (n *Node) FullText() string
- func (n *Node) HTML() string
- func (n *Node) Href() string
- func (n *Node) ID() string
- func (n *Node) IsElementNode() bool
- func (n *Node) IsTextNode() bool
- func (n *Node) LastChildNode() *Node
- func (n *Node) NextSiblingNode() *Node
- func (n *Node) ParentNode() *Node
- func (n *Node) PrevSiblingNode() *Node
- func (n *Node) Query(tag string, attrkv ...string) *Node
- func (n *Node) QueryAll(tag string, attrkv ...string) Nodes
- func (n *Node) Text() (text string)
- func (n *Node) Title() string
- func (n *Node) Walk(fn WalkFunc) error
- type Nodes
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
var ( SkipNode = errors.New("skip this node") SkipAll = errors.New("skip everything and stop the walk") )
Functions ¶
Types ¶
type Node ¶
func Parse ¶
Parse returns the parse tree for the HTML from the given Reader.
The input is assumed to be UTF-8 encoded.
func (*Node) Attributes ¶
Attributes returns all the attributes key-value map of this node.
func (*Node) ChildrenNodes ¶
Children returns all the direct child nodes of this node.
func (*Node) Find ¶
Find returns the first child element node matched by the specified tag and optional attribute key and value of this node.
It returns an error if no child element node is matched.
func (*Node) FirstChildNode ¶
FirstChildNode returns the first direct child node of this node.
func (*Node) FullText ¶
Text returns the text joined by all the child text nodes in depth order of this node.
func (*Node) IsElementNode ¶
IsElementNode returns whether is an element node.
func (*Node) IsTextNode ¶
IsTextNode returns whether is a text node.
func (*Node) LastChildNode ¶
LastChildNode returns the last direct child node of this node.
func (*Node) NextSiblingNode ¶
NextSiblingNode returns the next sibling node of this node.
func (*Node) ParentNode ¶
ParentNode returns the parent node of this node.
func (*Node) PrevSiblingNode ¶
PrevSiblingNode returns the previous sibling node of this node.
func (*Node) Query ¶
Query returns the first child element node matched by the specified tag and optional attribute key and value of this node.
It returns nil if no child element node is matched.
Allow chaining call.
func (*Node) QueryAll ¶
QueryAll returns the child element nodes matched by the specified tag and optional attribute key and value of this node.
It returns nil if no child element node is matched.
Allow chaining call.
type Nodes ¶
type Nodes []*Node
func (Nodes) Query ¶
Query returns all the first child element node matched by the specified tag and optional attribute key and value on each node of this nodes.
It returns nil if no child element node is matched.
Allow chaining call.
type WalkFunc ¶
WalkFunc is the type of the function called by Walk to visit each node.
The error result returned by the function controls how Walk continues.
- If the function returns the special value SkipNode, Walk skips the current node.
- If the function returns the special value SkipAll, Walk stops entirely and returns nil.
- If the function returns a non-nil error, Walk stops entirely and returns that error.