hq

package
v0.0.0-...-2cf7da5 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyText - empty text
	ErrEmptyText = errors.New("empty text")
	// ErrInvalidScanFormat - invalid fmt.Scan format
	ErrInvalidScanFormat = errors.New("invalid fmt.Scan format")
	// ErrUnmatchedScanFormat - unmatched fmt.Scan format
	ErrUnmatchedScanFormat = errors.New("unmatched fmt.Scan format")
)
View Source
var (
	// ErrNotFound - not found
	ErrNotFound = syscall.ENOENT
	// ErrBreak - break
	ErrBreak = syscall.ELOOP
	// ErrTooManyNodes - too may nodes
	ErrTooManyNodes = errors.New("too many nodes")
	// ErrInvalidNode  - invalid node
	ErrInvalidNode = errors.New("invalid node")
	// ErrNotTextNode  - not a text node
	ErrNotTextNode = errors.New("not a text node")
)

Functions

func AttributeVal

func AttributeVal(node *html.Node, k string) (v string, err error)

AttributeVal returns attribute k's value of a node.

func ChildEqualText

func ChildEqualText(node *html.Node, text string) bool

ChildEqualText checks if child node is TextNode and value is equal to text or not.

func ContainsClass

func ContainsClass(source string, v string) bool

ContainsClass checks class v is in source classes or not.

func ContainsText

func ContainsText(node *html.Node, text string) bool

ContainsText checks if node is TextNode and value contains text or not.

func EqualText

func EqualText(node *html.Node, text string) bool

EqualText checks if node is TextNode and value is equal to text or not.

func ExactText

func ExactText(node *html.Node) (string, error)

ExactText returns a text node's text.

func FirstChild

func FirstChild(node *html.Node, nodeType html.NodeType) (p *html.Node, err error)

FirstChild returns first nodeType node.

func LastChild

func LastChild(node *html.Node, nodeType html.NodeType) (p *html.Node, err error)

LastChild returns last nodeType node.

func Text

func Text(node *html.Node) string

Text extracts formatted node text.

Types

type NodeEnum

type NodeEnum interface {
	ForEach(filter func(node *html.Node) error)
}

NodeEnum - node enumerator

type NodeSet

type NodeSet struct {
	Data NodeEnum
	Err  error
}

NodeSet - node set

func NewSource

func NewSource(r io.Reader) (ret NodeSet)

NewSource creates the html document, and treats it as a node set.

func Nodes

func Nodes(nodes ...*html.Node) (ret NodeSet)

Nodes creates a fixed node set.

func (NodeSet) A

func (p NodeSet) A() (ret NodeSet)

A returns a nodes.

func (NodeSet) Any

func (p NodeSet) Any() (ret NodeSet)

Any returns deeply visiting node set.

func (NodeSet) AttrVal

func (p NodeSet) AttrVal(k string, exactlyOne ...bool) (text string, err error)

AttrVal returns node attriute k's value.

func (NodeSet) Attribute

func (p NodeSet) Attribute(k, v string) (ret NodeSet)

Attribute returns nodes whose attribute k's value is v.

func (NodeSet) Cache

func (p NodeSet) Cache() NodeSet

Cache caches node set.

func (NodeSet) CachedLen

func (p NodeSet) CachedLen() int

CachedLen returns cached len.

func (NodeSet) Child

func (p NodeSet) Child() (ret NodeSet)

Child returns child node set.

func (NodeSet) ChildEqualText

func (p NodeSet) ChildEqualText(text string) (ret NodeSet)

ChildEqualText returns node set whose child is TextNode and value is equal to text.

func (NodeSet) ChildN

func (p NodeSet) ChildN(level int) (ret NodeSet)

ChildN return N level's generation node set.

func (NodeSet) ChildrenAsText

func (p NodeSet) ChildrenAsText(doReplace bool) (ret NodeSet)

ChildrenAsText converts all children as text node.

func (NodeSet) Class

func (p NodeSet) Class(v string) (ret NodeSet)

Class returns nodes whose whose attribute `class`'s value is v.

func (NodeSet) Collect

func (p NodeSet) Collect() (items []*html.Node, err error)

Collect collects all nodes of the node set.

func (NodeSet) CollectOne

func (p NodeSet) CollectOne(exactly ...bool) (item *html.Node, err error)

CollectOne collects one node of a node set. If exactly is true, it returns ErrTooManyNodes when node set is more than one.

func (NodeSet) ContainsClass

func (p NodeSet) ContainsClass(v string) (ret NodeSet)

ContainsClass returns nodes whose attribute `class` contains v.

func (NodeSet) ContainsText

func (p NodeSet) ContainsText(text string) (ret NodeSet)

ContainsText returns node set who is TextNode and value contains text.

func (NodeSet) Div

func (p NodeSet) Div() (ret NodeSet)

Div returns div nodes.

func (NodeSet) Dump

func (p NodeSet) Dump() NodeSet

Dump calls `Printf` to dump.

func (NodeSet) Element

func (p NodeSet) Element(v interface{}) (ret NodeSet)

Element returns nodes whose element type is v.

func (NodeSet) EqualText

func (p NodeSet) EqualText(text string) (ret NodeSet)

EqualText returns node set who is TextNode and value is equal to text.

func (NodeSet) ExactText

func (p NodeSet) ExactText(exactlyOne ...bool) (text string, err error)

ExactText returns text node's text.

func (NodeSet) FirstChild

func (p NodeSet) FirstChild(nodeType html.NodeType) (ret NodeSet)

FirstChild returns first nodeType node as a node set.

func (NodeSet) FirstElementChild

func (p NodeSet) FirstElementChild() (ret NodeSet)

FirstElementChild returns first element node as a node set.

func (NodeSet) FirstTextChild

func (p NodeSet) FirstTextChild() (ret NodeSet)

FirstTextChild returns first text node as a node set.

func (NodeSet) ForEach

func (p NodeSet) ForEach(filter func(node NodeSet))

ForEach visits the node set.

func (NodeSet) H1

func (p NodeSet) H1() (ret NodeSet)

H1 returns h1 nodes.

func (NodeSet) H2

func (p NodeSet) H2() (ret NodeSet)

H2 returns h2 nodes.

func (NodeSet) H3

func (p NodeSet) H3() (ret NodeSet)

H3 returns h3 nodes.

func (NodeSet) H4

func (p NodeSet) H4() (ret NodeSet)

H4 returns h4 nodes.

func (NodeSet) Href

func (p NodeSet) Href(v string) (ret NodeSet)

Href returns nodes whose whose attribute `href`'s value is v.

func (NodeSet) HrefVal

func (p NodeSet) HrefVal(exactlyOne ...bool) (text string, err error)

HrefVal returns node attriute href's value.

func (NodeSet) ID

func (p NodeSet) ID(v string) (ret NodeSet)

ID returns nodes whose whose attribute `id`'s value is v.

func (NodeSet) Img

func (p NodeSet) Img() (ret NodeSet)

Img returns img nodes.

func (NodeSet) Int

func (p NodeSet) Int(exactlyOne ...bool) (v int, err error)

Int gets node's text and converts it into an integer.

func (NodeSet) LastChild

func (p NodeSet) LastChild(nodeType html.NodeType) (ret NodeSet)

LastChild returns last nodeType node as a node set.

func (NodeSet) LastElementChild

func (p NodeSet) LastElementChild() (ret NodeSet)

LastElementChild returns last element node as a node set.

func (NodeSet) LastTextChild

func (p NodeSet) LastTextChild() (ret NodeSet)

LastTextChild returns last text node as a node set.

func (NodeSet) Li

func (p NodeSet) Li() (ret NodeSet)

Li returns li nodes.

func (NodeSet) Match

func (p NodeSet) Match(filter func(node *html.Node) bool) (ret NodeSet)

Match filters the node set.

func (NodeSet) Nav

func (p NodeSet) Nav() (ret NodeSet)

Nav returns nav nodes.

func (NodeSet) NextSibling

func (p NodeSet) NextSibling(delta int) (ret NodeSet)

NextSibling returns next sibling node set.

func (NodeSet) NextSiblings

func (p NodeSet) NextSiblings() (ret NodeSet)

NextSiblings return all next sibling node set.

func (NodeSet) Ok

func (p NodeSet) Ok() bool

Ok returns if node set is valid or not.

func (NodeSet) Ol

func (p NodeSet) Ol() (ret NodeSet)

Ol returns ol nodes.

func (NodeSet) One

func (p NodeSet) One() (ret NodeSet)

One returns the first node as a node set.

func (NodeSet) Parent

func (p NodeSet) Parent() (ret NodeSet)

Parent return parent node set.

func (NodeSet) ParentN

func (p NodeSet) ParentN(level int) (ret NodeSet)

ParentN return N level's ancestor node set.

func (NodeSet) PrevSibling

func (p NodeSet) PrevSibling(delta int) (ret NodeSet)

PrevSibling returns prev sibling node set.

func (NodeSet) PrevSiblings

func (p NodeSet) PrevSiblings() (ret NodeSet)

PrevSiblings return all prev sibling node set.

func (NodeSet) Printf

func (p NodeSet) Printf(w io.Writer, format string, params ...interface{}) NodeSet

Printf prints all nodes.

func (NodeSet) ScanInt

func (p NodeSet) ScanInt(format string, exactlyOne ...bool) (v int, err error)

ScanInt gets node's text and scans it to an integer.

func (NodeSet) Span

func (p NodeSet) Span() (ret NodeSet)

Span returns span nodes.

func (NodeSet) Td

func (p NodeSet) Td() (ret NodeSet)

Td returns td nodes.

func (NodeSet) Text

func (p NodeSet) Text(exactlyOne ...bool) (text string, err error)

Text returns node's text

func (NodeSet) Ul

func (p NodeSet) Ul() (ret NodeSet)

Ul returns ul nodes.

func (NodeSet) UnitedFloat

func (p NodeSet) UnitedFloat(exactlyOne ...bool) (v float64, err error)

UnitedFloat gets node's text and converts it into a united float.

type SourceCreator

type SourceCreator struct{}

SourceCreator - hq source creator.

var (
	// Source - hq source creator
	Source SourceCreator
)

func (SourceCreator) Bytes

func (p SourceCreator) Bytes(text []byte) (ret NodeSet)

Bytes - a bytes hq source

func (SourceCreator) File

func (p SourceCreator) File(htmlFile string) (ret NodeSet)

File - a local file hq source

func (SourceCreator) HTTP

func (p SourceCreator) HTTP(url string) (ret NodeSet)

HTTP - a http hq source

func (SourceCreator) Reader

func (p SourceCreator) Reader(r io.Reader) (ret NodeSet)

Reader - a stream hq source

func (SourceCreator) Stdin

func (p SourceCreator) Stdin() (ret NodeSet)

Stdin - a stdin hq source

func (SourceCreator) String

func (p SourceCreator) String(text string) (ret NodeSet)

String - a string hq source

func (SourceCreator) URI

func (p SourceCreator) URI(uri string) (ret NodeSet)

URI - a uri hq source

Jump to

Keyboard shortcuts

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