Documentation
¶
Overview ¶
GOLANG HTML Parser
Parse HTML very easy.
Example:
HTML := "..." doc, err := html.Parse(strings.NewReader(HTML)) // handle error ... fmt.Println(doc.HTML()) element := doc.Find(&html.Match{ Name: "p", Attributes: map[string]string{"id": "pid"}, }) fmt.Println(element.Text())
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
func (*Element) AppendChild ¶
AppendChild adds a element c as a child of elem.
It will panic if c already has a parent or siblings.
it is shorthand for elem.Node.AppendChild(c.Node)
func (*Element) Clear ¶
func (elem *Element) Clear()
Clear deletes the tag from the tree of a given HTML.
type HTMLParser ¶
type HTMLParser struct {
// contains filtered or unexported fields
}
HTML Parser
func (HTMLParser) Find ¶
func (p HTMLParser) Find(selection *Match) *Element
Find returns first match
func (HTMLParser) FindAll ¶
func (p HTMLParser) FindAll(selection *Match) []*Element
FindAll returns all matches
func (HTMLParser) FindAllFunc ¶
func (p HTMLParser) FindAllFunc(selection *Match, f func(*Element))
type Match ¶
type Match struct { // Element name (e.g. head, title, a, div, ...) Name string // Tag attributes // // Example: // map[string]string{"id":"search"} // -> <element id="search" ...> // // map[string]string{"class":"nme"} // -> <element class="nme" ...> // // If you want only include attribute, pass empty string: // map[string]string{"href":""} // -> <element href="*" ...> Attributes map[string]string // Parent of element // <parent> // ... // <element> Parent *Match // First child of element // <element> // <child> FirstChild *Match }
Click to show internal directories.
Click to hide internal directories.