Documentation
¶
Overview ¶
runtime globals and utilities.
Index ¶
- Constants
- Variables
- func Click(el *Element, which InputMouseButton, count int)
- func ClosePage(page *Page) error
- func GetAttribute(el *Element, att string) string
- func GetElemText(elem *Element) string
- func GetPageText(page *Page) string
- func GetText(el *Element) string
- func Input(el *Element, txt string)
- func InputFrom(css string, txt string, pageOrElement Elementer)
- func MustSerialize(a any) string
- func NewSelectAllIterator[T Elementer](ctx context.Context, pageOrElement T, css string, limit int, xpath bool) *selectAllIteratorP
- func Pages() ([]any, error)
- func SafeSprintf(format string, a ...any) (result string, err error)
- func Serialize(a any) (string, error)
- func SetBrowserDataDir(dir string) (err error)
- func SetHeadless(h bool) error
- func SetIgnore(patt ...string) error
- type Browser
- type Element
- type Elementer
- type Elements
- type Hash
- type InputMouseButton
- type Iterator
- type Page
- type Unique
Constants ¶
const ( MouseLeft = InputMouseButton(proto.InputMouseButtonLeft) MouseRight = InputMouseButton(proto.InputMouseButtonRight) MouseMiddle = InputMouseButton(proto.InputMouseButtonMiddle) )
Variables ¶
var ( ErrNotUnique = fmt.Errorf("value is not unique") ErrNilFilter = fmt.Errorf("cannot use a nil Unique filter") )
var Errorf func(format string, args ...any)
Set these hooks to capture runtime errors orlog messages. If not set, will report to stdout.
var Logf func(format string, args ...any)
var SLOW_DELAY = 1 * time.Second
Default duration when SLOW is requested with invalid millis expression. Can be adjusted before running a request calling SLOW. Use for debugging only.
Functions ¶
func Click ¶
func Click(el *Element, which InputMouseButton, count int)
Click on an element. Use which to choose from "left", "right" or "middle" (default left). Use count to specify number of clicks (defaults 1).
func GetAttribute ¶ added in v0.4.9
Retrieve attribute from element. Return empty string on error.
func GetElemText ¶ added in v0.4.9
Get text for element. Never wait, never fail. Return "" if error.
func GetPageText ¶ added in v0.4.9
Return string content of the html element in page, or "" if error. Never abort, never wait.
func MustSerialize ¶ added in v0.4.9
See Serialize. Panic on error.
func NewSelectAllIterator ¶
func Pages ¶ added in v0.4.14
Get the array of opened pages. Note : returns a GSC array ([]any), not a []*rod.Page array.
func SafeSprintf ¶ added in v0.4.9
SafePrintf is like Sprintf, but return runtime formatting errors without panic
func Serialize ¶ added in v0.4.9
Serialize a value to string, using the GSC syntax. Only values produced by GSC itself can be serialized. Maps keys are sorted to guarantee determistic serialization. Non recognized values will trigger an error.
func SetBrowserDataDir ¶
The directory to save brawser internal states into (cookies, etc ...)
func SetHeadless ¶
Set browser in headless mode. Browser should not have started already.
Types ¶
type Elementer ¶
type Elementer interface {
Elements(string) (Elements, error)
ElementsX(string) (Elements, error)
Element(string) (*Element, error)
ElementX(string) (*Element, error)
}
Elementer can provide Elements or Element. Typically, a page or an element.
type InputMouseButton ¶ added in v0.4.9
type InputMouseButton = proto.InputMouseButton
defining type alias to decouple from actual driver.
type Iterator ¶
Generic iterator interface
func NewForLoopIterator ¶ added in v0.4.9
No enforcing on dangerous values, such as step = 0. May loop forever. It is not a bug, but a feature ;-).
func NewForLoopIteratorSafe ¶ added in v0.4.9
Same, but adjusts provided values to ensure no endless loops and positive direction.
type Unique ¶ added in v0.4.9
type Unique struct {
// contains filtered or unexported fields
}
Uniqueness filter, using a GSC Hash. Use u := new(Unique) to initialize it. Typically for RETURN DISTINCT. For rod.Element, you may prefer using element.Equal(element) to comprare actual DOM elements in browser.