supersimplesoup

package module
v0.0.0-...-7a3566c Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 7 Imported by: 8

Documentation

Overview

Package supersimplesoup implements a super simple soup like DOM API.

Index

Constants

This section is empty.

Variables

View Source
var (
	SkipNode = errors.New("skip this node")
	SkipAll  = errors.New("skip everything and stop the walk")
)

Functions

func Walk

func Walk(root *Node, fn WalkFunc) error

Walk walks the node tree rooted at root, calling fn for each node in the tree, including root.

The nodes are walked in depth first order, which makes the output deterministic.

Types

type Node

type Node html.Node

func Parse

func Parse(r io.Reader) (*Node, error)

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

The input is assumed to be UTF-8 encoded.

func (*Node) Attribute

func (n *Node) Attribute(key string) string

Attribute return the key specified attribute of this node.

func (*Node) Attributes

func (n *Node) Attributes() map[string]string

Attributes returns all the attributes key-value map of this node.

func (*Node) ChildrenNodes

func (n *Node) ChildrenNodes() (children []*Node)

Children returns all the direct child nodes of this node.

func (*Node) Class

func (n *Node) Class() string

Class returns the class attribute of this node.

func (*Node) Find

func (n *Node) Find(tag string, attrkv ...string) (*Node, error)

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

func (n *Node) FirstChildNode() *Node

FirstChildNode returns the first direct child node of this node.

func (*Node) FullText

func (n *Node) FullText() string

Text returns the text joined by all the child text nodes in depth order of this node.

func (*Node) HTML

func (n *Node) HTML() string

HTML returns the HTML source code of this node.

func (*Node) Href

func (n *Node) Href() string

Href returns the href attribute of this node.

func (*Node) ID

func (n *Node) ID() string

ID returns the id attribute of this node.

func (*Node) IsElementNode

func (n *Node) IsElementNode() bool

IsElementNode returns whether is an element node.

func (*Node) IsTextNode

func (n *Node) IsTextNode() bool

IsTextNode returns whether is a text node.

func (*Node) LastChildNode

func (n *Node) LastChildNode() *Node

LastChildNode returns the last direct child node of this node.

func (*Node) NextSiblingNode

func (n *Node) NextSiblingNode() *Node

NextSiblingNode returns the next sibling node of this node.

func (*Node) ParentNode

func (n *Node) ParentNode() *Node

ParentNode returns the parent node of this node.

func (*Node) PrevSiblingNode

func (n *Node) PrevSiblingNode() *Node

PrevSiblingNode returns the previous sibling node of this node.

func (*Node) Query

func (n *Node) Query(tag string, attrkv ...string) *Node

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

func (n *Node) QueryAll(tag string, attrkv ...string) Nodes

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.

func (*Node) Text

func (n *Node) Text() (text string)

Text returns the text joined by all the direct child text nodes of this node.

func (*Node) Title

func (n *Node) Title() string

Title returns the title attribute of this node.

func (*Node) Walk

func (n *Node) Walk(fn WalkFunc) error

Walk walks the node tree rooted at this node, calling fn for each node in the tree, including this node.

type Nodes

type Nodes []*Node

func (Nodes) Query

func (ns Nodes) Query(tag string, attrkv ...string) (found Nodes)

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.

func (Nodes) QueryAll

func (ns Nodes) QueryAll(tag string, attrkv ...string) (found Nodes)

QueryAll returns all the child element nodes 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

type WalkFunc func(node *Node) error

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.

Jump to

Keyboard shortcuts

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