Documentation ¶
Overview ¶
Package htmlquery provides extract data from HTML documents using XPath expression.
Index ¶
- Constants
- Variables
- func CSS2Xpath(css string, scope Scope) string
- func Find(top *html.Node, expr string) []*html.Node
- func FindOne(top *html.Node, expr string) *html.Node
- func InnerText(n *html.Node) string
- func LoadDoc(path string) (*html.Node, error)
- func LoadURL(url string) (*html.Node, error)
- func OutputHTML(n *html.Node, self bool) string
- func Parse(r io.Reader) (*html.Node, error)
- func Query(top *html.Node, expr string) (*html.Node, error)
- func QueryAll(top *html.Node, expr string) ([]*html.Node, error)
- func QuerySelector(top *html.Node, selector *xpath.Expr) *html.Node
- func QuerySelectorAll(top *html.Node, selector *xpath.Expr) []*html.Node
- func SelectAttr(n *html.Node, name string) (val string)
- type Lexeme
- type NodeNavigator
- func (h *NodeNavigator) Copy() xpath.NodeNavigator
- func (h *NodeNavigator) Current() *html.Node
- func (h *NodeNavigator) LocalName() string
- func (h *NodeNavigator) MoveTo(other xpath.NodeNavigator) bool
- func (h *NodeNavigator) MoveToChild() bool
- func (h *NodeNavigator) MoveToFirst() bool
- func (h *NodeNavigator) MoveToNext() bool
- func (h *NodeNavigator) MoveToNextAttribute() bool
- func (h *NodeNavigator) MoveToParent() bool
- func (h *NodeNavigator) MoveToPrevious() bool
- func (h *NodeNavigator) MoveToRoot()
- func (h *NodeNavigator) NodeType() xpath.NodeType
- func (*NodeNavigator) Prefix() string
- func (h *NodeNavigator) String() string
- func (h *NodeNavigator) Value() string
- type Scope
- type Selector
- type Selectors
Constants ¶
const ( SPACES = iota COMMA UNIVERSAL TYPE ELEMENT CLASS ID LBRACKET RBRACKET AttrName AttrValue EQUALS ContainsClass DashPrefixed StartsWith EndsWith CONTAINS MatchOp PseudoClass FirstChild FirstOfType NthChild NthOfType OnlyChild OnlyOfType LastChild LastOfType NOT LPAREN RPAREN COEFFICIENT SIGNED UNSIGNED ODD EVEN N OPERATOR PLUS MINUS BINOMIAL AdjacentTo PRECEDES ParentOf AncestorOf // and a counter ... I can't believe I didn't think of this sooner NumLexemes )
all types
const ( GLOBAL = iota LOCAL )
all Scopes
Variables ¶
var DisableSelectorCache = false
DisableSelectorCache will disable caching for the query selector if value is true.
var SelectorCacheMaxEntries = 100
SelectorCacheMaxEntries allows how many selector object can be caching. Default is 50. Will disable caching if SelectorCacheMaxEntries <= 0.
Functions ¶
func Find ¶
Find is like QueryAll but Will panics if the expression `expr` cannot be parsed.
See `QueryAll()` function.
func FindOne ¶
FindOne is like Query but will panics if the expression `expr` cannot be parsed. See `Query()` function.
func OutputHTML ¶
OutputHTML returns the text including tags name.
func Query ¶
Query searches the html.Node that matches by the specified XPath expr, and return the first element of matched html.Node.
Return an error if the expression `expr` cannot be parsed.
func QueryAll ¶
QueryAll searches the html.Node that matches by the specified XPath expr. Return an error if the expression `expr` cannot be parsed.
func QuerySelector ¶
QuerySelector returns the first matched html.Node by the specified XPath selector.
func QuerySelectorAll ¶
QuerySelectorAll searches all of the html.Node that matches the specified XPath selectors.
Types ¶
type NodeNavigator ¶
type NodeNavigator struct {
// contains filtered or unexported fields
}
func CreateXPathNavigator ¶
func CreateXPathNavigator(top *html.Node) *NodeNavigator
CreateXPathNavigator creates a new xpath.NodeNavigator for the specified html.Node.
func (*NodeNavigator) Copy ¶
func (h *NodeNavigator) Copy() xpath.NodeNavigator
func (*NodeNavigator) Current ¶
func (h *NodeNavigator) Current() *html.Node
func (*NodeNavigator) LocalName ¶
func (h *NodeNavigator) LocalName() string
func (*NodeNavigator) MoveTo ¶
func (h *NodeNavigator) MoveTo(other xpath.NodeNavigator) bool
func (*NodeNavigator) MoveToChild ¶
func (h *NodeNavigator) MoveToChild() bool
func (*NodeNavigator) MoveToFirst ¶
func (h *NodeNavigator) MoveToFirst() bool
func (*NodeNavigator) MoveToNext ¶
func (h *NodeNavigator) MoveToNext() bool
func (*NodeNavigator) MoveToNextAttribute ¶
func (h *NodeNavigator) MoveToNextAttribute() bool
func (*NodeNavigator) MoveToParent ¶
func (h *NodeNavigator) MoveToParent() bool
func (*NodeNavigator) MoveToPrevious ¶
func (h *NodeNavigator) MoveToPrevious() bool
func (*NodeNavigator) MoveToRoot ¶
func (h *NodeNavigator) MoveToRoot()
func (*NodeNavigator) NodeType ¶
func (h *NodeNavigator) NodeType() xpath.NodeType
func (*NodeNavigator) Prefix ¶
func (*NodeNavigator) Prefix() string
func (*NodeNavigator) String ¶
func (h *NodeNavigator) String() string
func (*NodeNavigator) Value ¶
func (h *NodeNavigator) Value() string