Documentation ¶
Index ¶
- func ElementToFile(e Element, out *os.File) (err error)
- type AttributeValidator
- type BaseElement
- func (e *BaseElement) AddChild(child Element)
- func (e *BaseElement) AllByAttribute(name, value string) []Element
- func (e *BaseElement) AllByClass(class string) []Element
- func (e *BaseElement) AllById(id string) []Element
- func (e *BaseElement) AllByTag(tag string) []Element
- func (e *BaseElement) ByAttribute(name, value string) Element
- func (e *BaseElement) ByClass(class string) Element
- func (e *BaseElement) ById(id string) Element
- func (e *BaseElement) ByTag(tag string) Element
- func (e *BaseElement) GetAttribute(key string) string
- func (e *BaseElement) GetAttributes() map[string]string
- func (e *BaseElement) GetChildren() []Element
- func (e *BaseElement) GetContent() string
- func (e *BaseElement) GetKind() ElemKind
- func (e *BaseElement) GetMutex() *sync.RWMutex
- func (e *BaseElement) GetParent() Element
- func (e *BaseElement) GetTagName() string
- func (e *BaseElement) Next() Element
- func (e *BaseElement) Prev() Element
- func (e *BaseElement) RemoveAttribute(key string)
- func (e *BaseElement) RemoveChild(child Element)
- func (e *BaseElement) SetAttribute(key, value string)
- func (e *BaseElement) SetContent(content string)
- func (e *BaseElement) SetKind(elemKind ElemKind)
- func (e *BaseElement) SetTagName(name string)
- func (e *BaseElement) String() string
- type BaseValidator
- type ElemKind
- type Element
- type Form
- func (e *Form) Action() string
- func (e *Form) ClearFields()
- func (e *Form) GetField(name string) string
- func (e *Form) GetFields() []Element
- func (e *Form) GetInputs() []Element
- func (e *Form) GetSelects() []Element
- func (e *Form) Method() string
- func (e *Form) Name() string
- func (e *Form) SetField(name, value string)
- type Input
- type Page
- func (p *Page) Absolutify()
- func (p *Page) AllByAttribute(name, value string) []Element
- func (p *Page) AllByClass(class string) []Element
- func (p *Page) AllById(id string) []Element
- func (p *Page) ByAttribute(name, value string) Element
- func (p *Page) ByClass(class string) Element
- func (p *Page) ById(id string) Element
- func (p *Page) GetUrl() string
- func (p *Page) SaveToFile(fileName string)
- func (p *Page) SetUrl(url string)
- type Parser
- type TagValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AttributeValidator ¶
type AttributeValidator struct { *BaseValidator Key, Val string }
Attribute Validator checks if an element contains a matching
attribute value pair
func NewAttributeValidator ¶
func NewAttributeValidator(key, text string) (*AttributeValidator, error)
Construct a AttributeValidator, text is the search term which can be a literal : Example: find all items of the "mytextwidget" class NewAttributeValidator("mytextwidget")
or a standard go regular expression: Example: perhaps we want to find all elements whose class begins with "mytext" NewAttributeValidator("mytext*")
func (AttributeValidator) Validate ¶
func (t AttributeValidator) Validate(e Element) bool
type BaseElement ¶
type BaseElement struct {
// contains filtered or unexported fields
}
Common base HTML Element implementation
func NewBaseElement ¶
func NewBaseElement() *BaseElement
func (*BaseElement) AddChild ¶
func (e *BaseElement) AddChild(child Element)
Append a child to a node and remove it from its old parent if it has one
func (*BaseElement) AllByAttribute ¶
func (e *BaseElement) AllByAttribute(name, value string) []Element
Return all elements found with the given attribute matching the given value.
Example: find all links where the url points to submit elem.ByAttribute("href", "/submit")
func (*BaseElement) AllByClass ¶
func (e *BaseElement) AllByClass(class string) []Element
Return the all element found with the given class.
Example: elem := elem.AllByClass("info-result")
func (*BaseElement) AllById ¶
func (e *BaseElement) AllById(id string) []Element
Return the all element found with the given id.
Example: find all links where the url points to submit elem := elem.ById("search-result")
func (*BaseElement) AllByTag ¶
func (e *BaseElement) AllByTag(tag string) []Element
Return the first element with a matching tag Example: find all forms in the document forms := elem.ByTag("form")
func (*BaseElement) ByAttribute ¶
func (e *BaseElement) ByAttribute(name, value string) Element
Return the first element found with a given attribute matching the given value. Usually used when there is only one of these elements on a page or any one of them will do.
Example: Return the first link with a url pointing to /search link := elem.ByAttribute("href", "/search")
func (*BaseElement) ByClass ¶
func (e *BaseElement) ByClass(class string) Element
Return the first element found with the given class name.
Example: Find the first (usually only) search box div box := elem.ByClass("info-container")
func (*BaseElement) ById ¶
func (e *BaseElement) ById(id string) Element
Return the first element found with the given id.
Example: Find the first (usually only) search box div box := elem.ById("search-box")
func (*BaseElement) ByTag ¶
func (e *BaseElement) ByTag(tag string) Element
Return the first element with a matching tag Example: find the first form in the document form := elem.ByTag("form")
func (*BaseElement) GetAttribute ¶
func (e *BaseElement) GetAttribute(key string) string
Return an Elements tag attribute Example: Read the css style attribute if present styleStr := elem.GetAttribute("style")
func (*BaseElement) GetAttributes ¶
func (e *BaseElement) GetAttributes() map[string]string
Get all tag attributes belonging to an element
func (*BaseElement) GetChildren ¶
func (e *BaseElement) GetChildren() []Element
Return all children directly below this element
func (*BaseElement) GetContent ¶
func (e *BaseElement) GetContent() string
Returns text enclosed within this elements start and end tags excluding any child tags.
func (*BaseElement) GetKind ¶
func (e *BaseElement) GetKind() ElemKind
func (*BaseElement) GetMutex ¶
func (e *BaseElement) GetMutex() *sync.RWMutex
func (*BaseElement) GetParent ¶
func (e *BaseElement) GetParent() Element
Return this childs current parent element
func (*BaseElement) GetTagName ¶
func (e *BaseElement) GetTagName() string
Return the tag name for an element such as "img" or "div"
func (*BaseElement) Next ¶
func (e *BaseElement) Next() Element
func (*BaseElement) Prev ¶
func (e *BaseElement) Prev() Element
func (*BaseElement) RemoveAttribute ¶
func (e *BaseElement) RemoveAttribute(key string)
Completely remove an attribute from an element Example: Remove all local formatting from an element elem.RemoveAttribute("style")
func (*BaseElement) RemoveChild ¶
func (e *BaseElement) RemoveChild(child Element)
Remove a child and all its children from a given elements tree
func (*BaseElement) SetAttribute ¶
func (e *BaseElement) SetAttribute(key, value string)
Set an Elements tag attribute Example: Use the style attribute to hide the element elem.SetAttribute("style","display:none")
func (*BaseElement) SetContent ¶
func (e *BaseElement) SetContent(content string)
Sets the text enclosed within this elements start and end tags excluding any child tags.
func (*BaseElement) SetKind ¶
func (e *BaseElement) SetKind(elemKind ElemKind)
func (*BaseElement) SetTagName ¶
func (e *BaseElement) SetTagName(name string)
Set the tag name of this Element to the given name
func (*BaseElement) String ¶
func (e *BaseElement) String() string
Return a textual representation of this element
type BaseValidator ¶
type BaseValidator struct { Text string // contains filtered or unexported fields }
Base Validator provides a basic default implementation of the Validator interface
func NewBaseValidator ¶
func NewBaseValidator(text string) (b *BaseValidator, err error)
Construct a Validator, text is the search term which can be a literal : Example: NewBaseValidator("my-content-div-01")
or a standard go regular expression: Example: NewBaseValidator("my-content-div*")
func (*BaseValidator) FirstOnly ¶
func (t *BaseValidator) FirstOnly() bool
func (*BaseValidator) GetRegex ¶
func (t *BaseValidator) GetRegex() *regexp.Regexp
func (*BaseValidator) SetFirstOnly ¶
func (t *BaseValidator) SetFirstOnly(first bool)
func (*BaseValidator) SetRegex ¶
func (t *BaseValidator) SetRegex(reg *regexp.Regexp)
func (*BaseValidator) Validate ¶
func (t *BaseValidator) Validate(e Element) bool
type Element ¶
type Element interface { AddChild(child Element) RemoveChild(child Element) GetParent() Element GetAttribute(key string) string SetAttribute(key, value string) RemoveAttribute(key string) GetTagName() string SetTagName(name string) GetChildren() []Element GetContent() string SetContent(string) String() string GetAttributes() map[string]string ByAttribute(name, value string) Element AllByAttribute(name, value string) []Element ById(id string) Element AllById(id string) []Element ByClass(class string) Element AllByClass(class string) []Element ByTag(tag string) Element AllByTag(tag string) []Element GetMutex() *sync.RWMutex GetKind() ElemKind SetKind(ElemKind) Next() Element Prev() Element // contains filtered or unexported methods }
Define common methods for HTML elements
type Form ¶
type Form struct { BaseElement Inputs *url.Values }
HTML <form> object
func (*Form) ClearFields ¶
func (e *Form) ClearFields()
func (*Form) GetSelects ¶
type Page ¶
func (*Page) Absolutify ¶
func (p *Page) Absolutify()
Convert all relative links on this page to absolute links (useful when saving a file to disk for later viewing)
func (*Page) AllByAttribute ¶
Find all elements matching a given attribute Example: result := page.AllAttribute("class","search-result-div")
func (*Page) AllByClass ¶
Find all elements with this class Example: result := page.AllById("news-result-div")
func (*Page) AllById ¶
Find all elements with this id Example: result := page.AllById("search-result-div")
func (*Page) ByAttribute ¶
Find the first element matching a given attribute Example: form := page.ByAttribute("id","login-form")
func (*Page) ByClass ¶
Find the first element with this class Example: form := page.ByClass("container-div")
func (*Page) SaveToFile ¶
Blocking call to save this pages html content to a file
type TagValidator ¶
type TagValidator struct { *BaseValidator // contains filtered or unexported fields }
TagValidator compares based on the value of the tag name
func NewTagValidator ¶
func NewTagValidator(tagName string) (*TagValidator, error)
Construct a TagValidator, text is the search term which can be a literal : Example: find all menu tags NewTagValidator("menu")
or a standard go regular expression: Example: perhaps we want to find all <menu> and <menuitem> tags NewTagValidator("menu*")
func (TagValidator) Validate ¶
func (t TagValidator) Validate(e Element) bool