engine

package
v0.0.0-...-c007042 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodePath

func NodePath(n *html.Node) []string

NodePath returns all the ancestors of node n, including itself as a string slice.

The nodes will be reconstructed into valid html.

func QuerySelector

func QuerySelector(n *html.Node) string

QuerySelector generates a query selector for the given html node.

func Reconstruct

func Reconstruct(n *html.Node) string

Reconstruct returns the html string used to generate the node n.

The text nodes associated with n will not be considered.

func SingleSelector

func SingleSelector(n *html.Node) string

SingleSelector generates a query selector for an html node. The result will not contain paths.

Types

type Query

type Query struct {
	Tag   string
	Attrs map[string]string
}

Query represents an html element. It is used for finding matches in a document.

func NewQuery

func NewQuery(s string) (*Query, error)

NewQuery parses a single html element and returns a Query instance.

Input must be a valid html element optionally wrapped with <>. If <> are prsent, they must be the first and the last characters respectively.

func (*Query) FindIn

func (q *Query) FindIn(r io.Reader) ([]*html.Node, error)

FindIn returns all the nodes matching the Query q.

It's the callers responsibility to ensure that the document is a valid utf-8 encoded string.

func (*Query) Match

func (q *Query) Match(n *html.Node) bool

Match checks if given node matches the query. Returns true if all attributes of q are present in n, and all values match.

func (*Query) Selector

func (q *Query) Selector() string

Selector returns a single selector for a Query.

Jump to

Keyboard shortcuts

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