html

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PagingType = core.NewType("paging")

Functions

func AttributeGet added in v0.7.0

func AttributeGet(ctx context.Context, args ...core.Value) (core.Value, error)

AttributeGet gets single or more attribute(s) of a given element. @param el (HTMLElement) - Target element. @param names (...String) - Attribute name(s). @returns Object - Key-value pairs of attribute values.

func AttributeRemove added in v0.7.0

func AttributeRemove(ctx context.Context, args ...core.Value) (core.Value, error)

AttributeRemove removes single or more attribute(s) of a given element. @param el (HTMLElement) - Target element. @param names (...String) - Attribute name(s).

func AttributeSet added in v0.7.0

func AttributeSet(ctx context.Context, args ...core.Value) (core.Value, error)

AttributeSet sets or updates a single or more attribute(s) of a given element. @param el (HTMLElement) - Target element. @param nameOrObj (String | Object) - Attribute name or an object representing a key-value pair of attributes. @param value (String) - If a second parameter is a string value, this parameter represent an attribute value.

func Click

func Click(ctx context.Context, args ...core.Value) (core.Value, error)

Click dispatches click event on a given element @param source (Document | Element) - Event source. @param selector (String, optional) - Optional selector. Only used when a document instance is passed.

func ClickAll

func ClickAll(ctx context.Context, args ...core.Value) (core.Value, error)

ClickAll dispatches click event on all matched element @param source (Document) - Document. @param selector (String) - Selector. @returns (Boolean) - Returns true if matched at least one element.

func CookieDel added in v0.7.0

func CookieDel(ctx context.Context, args ...core.Value) (core.Value, error)

CookieSet gets a cookie from a given document by name. @param source (HTMLDocument) - Target HTMLDocument. @param cookie (...HTTPCookie|String) - Cookie or cookie name to delete.

func CookieGet added in v0.7.0

func CookieGet(ctx context.Context, args ...core.Value) (core.Value, error)

CookieSet gets a cookie from a given document by name. @param doc (HTMLDocument) - Target HTMLDocument. @param name (String) - Cookie or cookie name to delete.

func CookieSet added in v0.7.0

func CookieSet(ctx context.Context, args ...core.Value) (core.Value, error)

CookieSet sets cookies to a given document @param doc (HTMLDocument) - Target document. @param cookie... (HTTPCookie) - Target cookies.

func Document

func Document(ctx context.Context, args ...core.Value) (core.Value, error)

Document loads a HTML document by a given url. By default, loads a document by http call - resulted document does not support any interactions. If passed "true" as a second argument, headless browser is used for loading the document which support interactions. @param url (String) - Target url string. If passed "about:blank" for dynamic document - it will open an empty page. @param isDynamicOrParams (Boolean|DocumentLoadParams) - Either a boolean value that indicates whether to use dynamic page or an object with the following properties :

dynamic (Boolean) - Optional, indicates whether to use dynamic page.
timeout (Int) - Optional, Document load timeout.

@returns (HTMLDocument) - Returns loaded HTML document.

func Download added in v0.3.0

func Download(_ context.Context, args ...core.Value) (core.Value, error)

Download a resource from the given URL. @param URL (String) - URL to download. @returns data (Binary) - Returns a base64 encoded string in binary format.

func Element

func Element(ctx context.Context, args ...core.Value) (core.Value, error)

Element finds an element by a given CSS selector. Returns NONE if element not found. @param docOrEl (HTMLDocument|HTMLElement) - Parent document or element. @param selector (String) - CSS selector. @returns (HTMLElement | None) - Returns an HTMLElement if found, otherwise NONE.

func ElementExists added in v0.6.0

func ElementExists(ctx context.Context, args ...core.Value) (core.Value, error)

ElementExists returns a boolean value indicating whether there is an element matched by selector. @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. @param selector (String) - CSS selector. @returns (Boolean) - A boolean value indicating whether there is an element matched by selector.

func Elements

func Elements(ctx context.Context, args ...core.Value) (core.Value, error)

Elements finds HTML elements by a given CSS selector. Returns an empty array if element not found. @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. @param selector (String) - CSS selector. @returns (Array) - Returns an array of found HTML element.

func ElementsCount

func ElementsCount(ctx context.Context, args ...core.Value) (core.Value, error)

ElementsCount returns a number of found HTML elements by a given CSS selector. Returns an empty array if element not found. @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element. @param selector (String) - CSS selector. @returns (Int) - A number of found HTML elements by a given CSS selector.

func Hover added in v0.5.0

func Hover(ctx context.Context, args ...core.Value) (core.Value, error)

Hover fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to hover over the center of the element. If there's no element matching selector, the method returns an error. @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. @param selector (String, options) - If document is passed, this param must represent an element selector.

func InnerHTML

func InnerHTML(ctx context.Context, args ...core.Value) (core.Value, error)

InnerHTML Returns inner HTML string of a given or matched by CSS selector element @param doc (Document|Element) - Parent document or element. @param selector (String, optional) - String of CSS selector. @returns (String) - Inner HTML string if an element found, otherwise empty string.

func InnerHTMLAll

func InnerHTMLAll(ctx context.Context, args ...core.Value) (core.Value, error)

InnerHTMLAll returns an array of inner HTML strings of matched elements. @param doc (HTMLDocument|HTMLElement) - Parent document or element. @param selector (String) - String of CSS selector. @returns (String) - An array of inner HTML strings if any element found, otherwise empty array.

func InnerText

func InnerText(ctx context.Context, args ...core.Value) (core.Value, error)

InnerText returns inner text string of a given or matched by CSS selector element @param doc (HTMLDocument|HTMLElement) - Parent document or element. @param selector (String, optional) - String of CSS selector. @returns (String) - Inner text if an element found, otherwise empty string.

func InnerTextAll

func InnerTextAll(ctx context.Context, args ...core.Value) (core.Value, error)

InnerTextAll returns an array of inner text of matched elements. @param doc (HTMLDocument|HTMLElement) - Parent document or element. @param selector (String) - String of CSS selector. @returns (String) - An array of inner text if any element found, otherwise empty array.

func Input

func Input(ctx context.Context, args ...core.Value) (core.Value, error)

Input types a value to an underlying input element. @param source (Document | Element) - Event target. @param valueOrSelector (String) - Selector or a value. @param value (String) - Target value. @param delay (Int, optional) - Waits delay milliseconds between keystrokes @returns (Boolean) - Returns true if an element was found.

func MouseMoveXY added in v0.7.0

func MouseMoveXY(ctx context.Context, args ...core.Value) (core.Value, error)

MouseMoveXY moves mouse by given coordinates. @param doc (HTMLDocument) - HTML document. @param x (Int|Float) - X coordinate. @param y (Int|Float) - Y coordinate.

func Navigate(ctx context.Context, args ...core.Value) (core.Value, error)

Navigate navigates a document to a new resource. The operation blocks the execution until the page gets loaded. Which means there is no need in WAIT_NAVIGATION function. @param doc (Document) - Target document. @param url (String) - Target url to navigate. @param timeout (Int, optional) - Optional timeout. Default is 5000.

func NavigateBack(ctx context.Context, args ...core.Value) (core.Value, error)

NavigateBack navigates a document back within its navigation history. The operation blocks the execution until the page gets loaded. If the history is empty, the function returns FALSE. @param doc (Document) - Target document. @param entry (Int, optional) - Optional value indicating how many pages to skip. Default 1. @param timeout (Int, optional) - Optional timeout. Default is 5000. @returns (Boolean) - Returns TRUE if history exists and the operation succeeded, otherwise FALSE.

func NavigateForward(ctx context.Context, args ...core.Value) (core.Value, error)

NavigateForward navigates a document forward within its navigation history. The operation blocks the execution until the page gets loaded. If the history is empty, the function returns FALSE. @param doc (Document) - Target document. @param entry (Int, optional) - Optional value indicating how many pages to skip. Default 1. @param timeout (Int, optional) - Optional timeout. Default is 5000. @returns (Boolean) - Returns TRUE if history exists and the operation succeeded, otherwise FALSE.

func NewLib

func NewLib() map[string]core.Function

func PDF

func PDF(ctx context.Context, args ...core.Value) (core.Value, error)

PDF print a PDF of the current page. @param source (Document) - Document. @param params (Object) - Optional, An object containing the following properties :

Landscape (Bool) - Paper orientation. Defaults to false.
DisplayHeaderFooter (Bool) - Display header and footer. Defaults to false.
PrintBackground (Bool) - Print background graphics. Defaults to false.
Scale (Float64) - Scale of the webpage rendering. Defaults to 1.
PaperWidth (Float64) - Paper width in inches. Defaults to 8.5 inches.
PaperHeight (Float64) - Paper height in inches. Defaults to 11 inches.
MarginTop (Float64) - Top margin in inches. Defaults to 1cm (~0.4 inches).
MarginBottom (Float64) - Bottom margin in inches. Defaults to 1cm (~0.4 inches).
MarginLeft (Float64) - Left margin in inches. Defaults to 1cm (~0.4 inches).
MarginRight (Float64) - Right margin in inches. Defaults to 1cm (~0.4 inches).
PageRanges (String) - Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
IgnoreInvalidPageRanges (Bool) - to silently ignore invalid but successfully parsed page ranges, such as '3-2'. Defaults to false.
HeaderTemplate (String) - HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - `date`: formatted print date - `title`: document title - `url`: document location - `pageNumber`: current page number - `totalPages`: total pages in the document For example, `<span class=title></span>` would generate span containing the title.
FooterTemplate (String) - HTML template for the print footer. Should use the same format as the `headerTemplate`.
PreferCSSPageSize (Bool) - Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size. *

@returns data (Binary) - Returns a base64 encoded string in binary format.

func Pagination added in v0.5.0

func Pagination(_ context.Context, args ...core.Value) (core.Value, error)

Pagination creates an iterator that goes through pages using CSS selector. The iterator starts from the current page i.e. it does not change the page on 1st iteration. That allows you to keep scraping logic inside FOR loop. @param doc (Document) - Target document. @param selector (String) - CSS selector for a pagination on the page.

func Screenshot

func Screenshot(ctx context.Context, args ...core.Value) (core.Value, error)

Screenshot takes a screenshot of the current page. @param source (Document) - Document. @param params (Object) - Optional, An object containing the following properties :

x (Float|Int) - Optional, X position of the viewport.
x (Float|Int) - Optional,Y position of the viewport.
width (Float|Int) - Optional, Width of the viewport.
height (Float|Int) - Optional, Height of the viewport.
format (String) - Optional, Either "jpeg" or "png".
quality (Int) - Optional, Quality, in [0, 100], only for jpeg format.

@returns data (Binary) - Returns a base64 encoded string in binary format.

func ScrollBottom added in v0.5.0

func ScrollBottom(ctx context.Context, args ...core.Value) (core.Value, error)

ScrollTop scrolls the document's window to its bottom. @param doc (HTMLDocument) - Target document.

func ScrollInto added in v0.5.0

func ScrollInto(ctx context.Context, args ...core.Value) (core.Value, error)

ScrollInto scrolls an element on. @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. @param selector (String, options) - If document is passed, this param must represent an element selector.

func ScrollTop added in v0.5.0

func ScrollTop(ctx context.Context, args ...core.Value) (core.Value, error)

ScrollTop scrolls the document's window to its top. @param doc (HTMLDocument) - Target document.

func ScrollXY added in v0.7.0

func ScrollXY(ctx context.Context, args ...core.Value) (core.Value, error)

ScrollXY scrolls by given coordinates. @param doc (HTMLDocument) - HTML document. @param x (Int|Float) - X coordinate. @param y (Int|Float) - Y coordinate.

func Select added in v0.5.0

func Select(ctx context.Context, args ...core.Value) (core.Value, error)

Select selects a value from an underlying select element. @param source (Document | Element) - Event target. @param valueOrSelector (String | Array<String>) - Selector or a an array of strings as a value. @param value (Array<String) - Target value. Optional. @returns (Array<String>) - Returns an array of selected values.

func StyleGet added in v0.7.0

func StyleGet(ctx context.Context, args ...core.Value) (core.Value, error)

StyleGet gets single or more style attribute value(s) of a given element. @param el (HTMLElement) - Target element. @param names (...String) - Style name(s). @returns Object - Key-value pairs of style values.

func StyleRemove added in v0.7.0

func StyleRemove(ctx context.Context, args ...core.Value) (core.Value, error)

StyleRemove removes single or more style attribute value(s) of a given element. @param el (HTMLElement) - Target element. @param names (...String) - Style name(s).

func StyleSet added in v0.7.0

func StyleSet(ctx context.Context, args ...core.Value) (core.Value, error)

StyleSet sets or updates a single or more style attribute value of a given element. @param el (HTMLElement) - Target element. @param nameOrObj (String | Object) - Style name or an object representing a key-value pair of attributes. @param value (String) - If a second parameter is a string value, this parameter represent a style value.

func ValidateDocument

func ValidateDocument(ctx context.Context, value core.Value) (core.Value, error)

func ValidatePageRanges

func ValidatePageRanges(pageRanges string) (bool, error)

func WaitAttribute added in v0.7.0

func WaitAttribute(ctx context.Context, args ...core.Value) (core.Value, error)

func WaitAttributeAll added in v0.7.0

func WaitAttributeAll(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClassAll waits for a class to appear on all matched elements. Stops the execution until the navigation ends or operation times out. @param doc (HTMLDocument) - Parent document. @param selector (String) - String of CSS selector. @param class (String) - String of target CSS class. @param timeout (Int, optional) - Optional timeout.

func WaitClass

func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClass waits for a class to appear on a given element. Stops the execution until the navigation ends or operation times out. @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. @param selectorOrClass (String) - If document is passed, this param must represent an element selector. Otherwise target class. @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name. Otherwise timeout. @param timeout (Int, optional) - If document is passed, this param must represent timeout. Otherwise not passed.

func WaitClassAll

func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClassAll waits for a class to appear on all matched elements. Stops the execution until the navigation ends or operation times out. @param doc (HTMLDocument) - Parent document. @param selector (String) - String of CSS selector. @param class (String) - String of target CSS class. @param timeout (Int, optional) - Optional timeout.

func WaitElement

func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error)

WaitElement waits for element to appear in the DOM. Stops the execution until it finds an element or operation times out. @param doc (HTMLDocument) - Driver HTMLDocument. @param selector (String) - Target element's selector. @param timeout (Int, optional) - Optional timeout. Default 5000 ms.

func WaitNavigation

func WaitNavigation(ctx context.Context, args ...core.Value) (core.Value, error)

WaitNavigation waits for document to navigate to a new url. Stops the execution until the navigation ends or operation times out. @param doc (HTMLDocument) - Driver HTMLDocument. @param timeout (Int, optional) - Optional timeout. Default 5000 ms.

func WaitNoAttribute added in v0.7.0

func WaitNoAttribute(ctx context.Context, args ...core.Value) (core.Value, error)

func WaitNoAttributeAll added in v0.7.0

func WaitNoAttributeAll(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClassAll waits for a class to disappear on all matched elements. Stops the execution until the navigation ends or operation times out. @param doc (HTMLDocument) - Parent document. @param selector (String) - String of CSS selector. @param class (String) - String of target CSS class. @param timeout (Int, optional) - Optional timeout.

func WaitNoClass added in v0.7.0

func WaitNoClass(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClass waits for a class to disappear on a given element. Stops the execution until the navigation ends or operation times out. @param docOrEl (HTMLDocument|HTMLElement) - Target document or element. @param selectorOrClass (String) - If document is passed, this param must represent an element selector. Otherwise target class. @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name. Otherwise timeout. @param timeout (Int, optional) - If document is passed, this param must represent timeout. Otherwise not passed.

func WaitNoClassAll added in v0.7.0

func WaitNoClassAll(ctx context.Context, args ...core.Value) (core.Value, error)

WaitClassAll waits for a class to disappear on all matched elements. Stops the execution until the navigation ends or operation times out. @param doc (HTMLDocument) - Parent document. @param selector (String) - String of CSS selector. @param class (String) - String of target CSS class. @param timeout (Int, optional) - Optional timeout.

func WaitNoElement added in v0.7.0

func WaitNoElement(ctx context.Context, args ...core.Value) (core.Value, error)

WaitNoElements waits for element to disappear in the DOM. Stops the execution until it does not find an element or operation times out. @param doc (HTMLDocument) - Driver HTMLDocument. @param selector (String) - Target element's selector. @param timeout (Int, optional) - Optional timeout. Default 5000 ms.

func WaitNoStyle added in v0.7.0

func WaitNoStyle(ctx context.Context, args ...core.Value) (core.Value, error)

func WaitNoStyleAll added in v0.7.0

func WaitNoStyleAll(ctx context.Context, args ...core.Value) (core.Value, error)

func WaitStyle added in v0.7.0

func WaitStyle(ctx context.Context, args ...core.Value) (core.Value, error)

func WaitStyleAll added in v0.7.0

func WaitStyleAll(ctx context.Context, args ...core.Value) (core.Value, error)

Types

type DocumentLoadParams added in v0.6.0

type DocumentLoadParams struct {
	drivers.LoadDocumentParams
	Driver  string
	Timeout time.Duration
}

type Paging added in v0.5.0

type Paging struct {
	// contains filtered or unexported fields
}

func (*Paging) Compare added in v0.5.0

func (p *Paging) Compare(_ core.Value) int64

func (*Paging) Copy added in v0.5.0

func (p *Paging) Copy() core.Value

func (*Paging) Hash added in v0.5.0

func (p *Paging) Hash() uint64

func (*Paging) Iterate added in v0.5.0

func (p *Paging) Iterate(_ context.Context) (core.Iterator, error)

func (*Paging) MarshalJSON added in v0.5.0

func (p *Paging) MarshalJSON() ([]byte, error)

func (*Paging) String added in v0.5.0

func (p *Paging) String() string

func (*Paging) Type added in v0.5.0

func (p *Paging) Type() core.Type

func (*Paging) Unwrap added in v0.5.0

func (p *Paging) Unwrap() interface{}

type PagingIterator added in v0.5.0

type PagingIterator struct {
	// contains filtered or unexported fields
}

func (*PagingIterator) Next added in v0.5.0

Jump to

Keyboard shortcuts

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