http

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 23 Imported by: 1

README

http for GoJS

usage

import (
	"apigo.cc/gojs"
	_ "apigo.cc/gojs/http"
)

func main() {
	r, err := gojs.Run(`
import http from 'apigo.cc/gojs/http'

function main(args){
	return http.get('http://......')
}
	`, "test.js")

    fmt.Println(r, err)
}

websocket

import http from 'apigo.cc/gojs/http'
let conn http.connect('ws://......')
conn.write('hello world')
let r = conn.read()
conn.close()

module.exports

function new(config?: Config): Client
function newH2C(config?: Config): Client
function get(url: string, headers?: Object): Result
function head(url: string, headers?: Object): Result
function post(url: string, data: any, headers?: Object): Result
function put(url: string, data: any, headers?: Object): Result
function delete(url: string, data: any, headers?: Object): Result
function do(method: string, url: string, data: any, callback?: (data: string) => void, headers?: Object): Result
function upload(url: string, form: Object, files: Object, headers?: Object): Result
function download(filename: string, url: string, callback?: (finished: number, total: number) => void, headers?: Object): Result
function connect(url: string, config?: WSConfig): WS

full api see http.ts

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyMap = map[string]input.Key{}/* 182 elements not displayed */

Functions

func CloseAllChrome added in v0.0.4

func CloseAllChrome(vm *goja.Runtime)

Types

type Chrome added in v0.0.4

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

func StartChrome added in v0.0.4

func StartChrome(opt *ChromeOption, vm *goja.Runtime) (*Chrome, error)

func (*Chrome) Close added in v0.0.4

func (ch *Chrome) Close(vm *goja.Runtime)

func (*Chrome) Info added in v0.0.7

func (ch *Chrome) Info(showWindow *bool, vm *goja.Runtime) (ChromeInfo, error)

func (*Chrome) Open added in v0.0.4

func (ch *Chrome) Open(url string) (*Page, error)

type ChromeInfo added in v0.0.7

type ChromeInfo struct {
	ProtocolVersion string
	Product         string
	Revision        string
	UserAgent       string
	JsVersion       string
	ChromeURL       string
	ChromePath      string
}

type ChromeOption added in v0.0.7

type ChromeOption struct {
	ChromeURL      string
	ChromeOption   []string
	ShowWindow     bool
	ChromeHtpProxy string
}

type Element added in v0.0.4

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

func (*Element) AddClass added in v0.0.4

func (el *Element) AddClass(className string) error

func (*Element) Check added in v0.0.4

func (el *Element) Check() error

Check 勾选复选框

func (*Element) Children added in v0.0.4

func (el *Element) Children() ([]*Element, error)

Children 获取所有直接子元素

func (*Element) Click added in v0.0.4

func (el *Element) Click() error

func (*Element) Find added in v0.0.4

func (el *Element) Find(selector string) (*Element, error)

Find 在当前元素下查找匹配选择器的第一个元素

func (*Element) FindAll added in v0.0.4

func (el *Element) FindAll(selector string) ([]*Element, error)

FindAll 在当前元素下查找所有匹配选择器的元素

func (*Element) FindAllX added in v0.0.4

func (el *Element) FindAllX(selector string) ([]*Element, error)

FindAll 在当前元素下查找所有匹配选择器的元素

func (*Element) FindChild added in v0.0.4

func (el *Element) FindChild(selector string) (*Element, error)

Find 在当前元素下查找匹配选择器的第一个元素

func (*Element) FindChildN added in v0.0.4

func (el *Element) FindChildN(selector string) *Element

func (*Element) FindChildren added in v0.0.4

func (el *Element) FindChildren(selector string) ([]*Element, error)

FindAll 在当前元素下查找所有匹配选择器的元素

func (*Element) FindN added in v0.0.4

func (el *Element) FindN(selector string) *Element

func (*Element) FindParent added in v0.0.4

func (el *Element) FindParent(selector string) (*Element, error)

FindParent 向上查找匹配选择器的父元素

func (*Element) FindParentN added in v0.0.4

func (el *Element) FindParentN(selector string) *Element

func (*Element) FindParentX added in v0.0.4

func (el *Element) FindParentX(selector string) (*Element, error)

FindParent 向上查找匹配选择器的父元素

func (*Element) FindParentXN added in v0.0.4

func (el *Element) FindParentXN(selector string) *Element

func (*Element) FindX added in v0.0.4

func (el *Element) FindX(selector string) (*Element, error)

Find 在当前元素下查找匹配选择器的第一个元素

func (*Element) FindXN added in v0.0.4

func (el *Element) FindXN(selector string) *Element

func (*Element) Focus added in v0.0.4

func (el *Element) Focus() error

func (*Element) GetAttribute added in v0.0.4

func (el *Element) GetAttribute(name string) (*string, error)

GetAttribute 获取元素属性值 name: 属性名称 返回值: 属性值字符串,若不存在则返回空字符串

func (*Element) GetBoundingRect added in v0.0.4

func (el *Element) GetBoundingRect() (*Rect, error)

func (*Element) GetCenter added in v0.0.4

func (el *Element) GetCenter() (*Position, error)

func (*Element) GetChecked added in v0.0.4

func (el *Element) GetChecked() ([]string, error)

GetSelectedValues 获取当前选中的值(单选返回字符串,多选返回切片)

func (*Element) GetClass added in v0.0.4

func (el *Element) GetClass() ([]string, error)

func (*Element) GetComputedStyle added in v0.0.4

func (el *Element) GetComputedStyle() (map[string]string, error)

GetComputedStyle 获取元素所有计算样式

func (*Element) GetForm added in v0.0.4

func (el *Element) GetForm() (*Element, error)

GetForm 获取当前元素所属的表单

func (*Element) GetFormData added in v0.0.4

func (el *Element) GetFormData() (map[string]string, error)

GetFormData 获取表单数据

func (*Element) GetID added in v0.0.4

func (el *Element) GetID() (*string, error)

GetID 获取元素ID

func (*Element) GetName added in v0.0.4

func (el *Element) GetName() (*string, error)

GetName 获取元素名称(如<input name="username">)

func (*Element) GetOptions added in v0.0.4

func (el *Element) GetOptions() ([]map[string]string, error)

GetAllOptions 获取所有选项(值和文本)

func (*Element) GetPosition added in v0.0.4

func (el *Element) GetPosition() (*Position, error)

GetPosition 获取元素位置(中心点)

func (*Element) GetProperty added in v0.0.4

func (el *Element) GetProperty(name string) (interface{}, error)

GetProperty 获取 JavaScript 属性值 name: 属性名称 返回值: 属性值(interface{} 类型)

func (*Element) GetStyle added in v0.0.4

func (el *Element) GetStyle(property string) (string, error)

GetStyle 获取指定CSS样式值

func (*Element) GetType added in v0.0.4

func (el *Element) GetType() (*string, error)

GetType 获取元素类型(如"text"/"checkbox"等)

func (*Element) GetValue added in v0.0.4

func (el *Element) GetValue() (string, error)

GetValue 获取表单元素的值

func (*Element) HasAttribute added in v0.0.4

func (el *Element) HasAttribute(name string) (bool, error)

HasAttribute 检查属性是否存在

func (*Element) HasProperty added in v0.0.4

func (el *Element) HasProperty(name string) (bool, error)

HasProperty 检查属性是否存在

func (*Element) Hover added in v0.0.4

func (el *Element) Hover() error

func (*Element) InnerHTML added in v0.0.4

func (el *Element) InnerHTML() (string, error)

func (*Element) Input added in v0.0.4

func (el *Element) Input(text string) error

func (*Element) IsChecked added in v0.0.4

func (el *Element) IsChecked() (bool, error)

IsChecked 获取复选框/单选框的选中状态

func (*Element) IsDisabled added in v0.0.4

func (el *Element) IsDisabled() (bool, error)

IsDisabled 判断元素是否被禁用

func (*Element) IsInteractable added in v0.0.4

func (el *Element) IsInteractable() (bool, error)

IsInteractable 元素是否可交互

func (*Element) IsVisible added in v0.0.4

func (el *Element) IsVisible() (bool, error)

IsVisible 判断元素是否可见

func (*Element) Key added in v0.0.6

func (el *Element) Key(keys ...string) error

func (*Element) KeyPress added in v0.0.6

func (el *Element) KeyPress(keys ...string) error

元素级

func (*Element) KeyRelease added in v0.0.6

func (el *Element) KeyRelease(keys ...string) error

func (*Element) KeyType added in v0.0.6

func (el *Element) KeyType(keys ...string) error

func (*Element) OuterHTML added in v0.0.4

func (el *Element) OuterHTML() (string, error)

func (*Element) Parent added in v0.0.4

func (el *Element) Parent() (*Element, error)

Parent 获取直接父元素

func (*Element) RadioGroupValue added in v0.0.4

func (el *Element) RadioGroupValue() (string, error)

RadioGroupValue 获取单选按钮组的当前值

func (*Element) RemoveAttribute added in v0.0.4

func (el *Element) RemoveAttribute(name string) error

RemoveAttribute 移除元素属性 name: 要移除的属性名称

func (*Element) RemoveClass added in v0.0.4

func (el *Element) RemoveClass(className string) error

func (*Element) RemoveProperty added in v0.0.4

func (el *Element) RemoveProperty(name string) error

func (*Element) ScrollIntoView added in v0.0.4

func (el *Element) ScrollIntoView() error

func (*Element) Select added in v0.0.4

func (el *Element) Select(values ...string) error

Select 选择下拉框的选项(单选或多选)

func (*Element) SelectByText added in v0.0.4

func (el *Element) SelectByText(text string) error

SelectByText 通过文本选择选项

func (*Element) SelectByValue added in v0.0.4

func (el *Element) SelectByValue(value string) error

SelectByValue 通过值选择选项

func (*Element) SetAttribute added in v0.0.4

func (el *Element) SetAttribute(name, value string) error

SetAttribute 设置元素属性值 name: 属性名称 value: 属性值

func (*Element) SetChecked added in v0.0.4

func (el *Element) SetChecked(checked bool) error

SetChecked 设置复选框/单选框的选中状态

func (*Element) SetInnerHTML added in v0.0.4

func (el *Element) SetInnerHTML(html string) error

func (*Element) SetProperty added in v0.0.4

func (el *Element) SetProperty(name string, value interface{}) error

SetProperty 设置 JavaScript 属性 name: 属性名称 value: 属性值(可以是任意类型)

func (*Element) SetRadioGroupValue added in v0.0.4

func (el *Element) SetRadioGroupValue(value string) error

SetRadioGroupValue 设置单选按钮组的值

func (*Element) SetRadioValue added in v0.0.4

func (el *Element) SetRadioValue(value string) error

SetRadioValue 设置单选框值

func (*Element) SetStyle added in v0.0.4

func (el *Element) SetStyle(property, value string) error

SetStyle 设置CSS样式

func (*Element) SetText added in v0.0.4

func (el *Element) SetText(text string) error

func (*Element) SetValue added in v0.0.4

func (el *Element) SetValue(value string) error

SetValue 设置表单元素的值(input/textarea)

func (*Element) Submit added in v0.0.4

func (el *Element) Submit() error

Submit 提交表单(必须在FORM元素上调用)

func (*Element) Text added in v0.0.4

func (el *Element) Text() (string, error)

func (*Element) Uncheck added in v0.0.4

func (el *Element) Uncheck() error

Uncheck 取消勾选

func (*Element) UploadFile added in v0.0.4

func (el *Element) UploadFile(filePaths []string) error

func (*Element) WaitEnabled added in v0.0.4

func (el *Element) WaitEnabled() error

func (*Element) WaitInvisible added in v0.0.4

func (el *Element) WaitInvisible() error

func (*Element) WaitStable added in v0.0.4

func (el *Element) WaitStable(ms *int) error

func (*Element) WaitVisible added in v0.0.4

func (el *Element) WaitVisible() error

type Http

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

func (*Http) Connect

func (hc *Http) Connect(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Delete

func (hc *Http) Delete(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Do

func (hc *Http) Do(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Download

func (hc *Http) Download(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Get

func (hc *Http) Get(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Head

func (hc *Http) Head(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Post

func (hc *Http) Post(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Put

func (hc *Http) Put(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*Http) Upload

func (hc *Http) Upload(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

type Page added in v0.0.4

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

func (*Page) AccepDialog added in v0.0.4

func (pg *Page) AccepDialog() error

AutoAcceptAlerts 自动接受所有弹框

func (*Page) Back added in v0.0.4

func (pg *Page) Back() error

func (*Page) Close added in v0.0.4

func (pg *Page) Close() error

func (*Page) DismissDialog added in v0.0.4

func (pg *Page) DismissDialog() error

AutoDismissAlerts 自动取消所有弹框

func (*Page) Eval added in v0.0.4

func (pg *Page) Eval(js string) (interface{}, error)

func (*Page) Find added in v0.0.4

func (pg *Page) Find(selector string) (*Element, error)

func (*Page) FindAll added in v0.0.4

func (pg *Page) FindAll(selector string) ([]*Element, error)

func (*Page) FindAllX added in v0.0.4

func (pg *Page) FindAllX(xpath string) ([]*Element, error)

FindsX 通过XPath查找多个元素

func (*Page) FindN added in v0.0.4

func (pg *Page) FindN(selector string) *Element

func (*Page) FindX added in v0.0.4

func (pg *Page) FindX(xpath string) (*Element, error)

FindX 通过XPath查找元素

func (*Page) FindXN added in v0.0.4

func (pg *Page) FindXN(selector string) *Element

func (*Page) Forward added in v0.0.4

func (pg *Page) Forward() error

func (*Page) Frame added in v0.0.4

func (pg *Page) Frame(selector string) (*Page, error)

Frame 获取iframe内容

func (*Page) GetCookies added in v0.0.4

func (pg *Page) GetCookies() (map[string]string, error)

func (*Page) GetResContent added in v0.0.4

func (pg *Page) GetResContent(url string) ([]byte, error)

func (*Page) GetResList added in v0.0.4

func (pg *Page) GetResList() ([]Resource, error)

func (*Page) GetResListByMimeType added in v0.0.4

func (pg *Page) GetResListByMimeType(mimeType string) ([]Resource, error)

func (*Page) GetResListByType added in v0.0.4

func (pg *Page) GetResListByType(resType string) ([]Resource, error)

func (*Page) HandleDialog added in v0.0.4

func (pg *Page) HandleDialog(accept bool, promptText string) error

HandleDialog 设置弹框处理器 示例:pg.HandleDialog(true, "") 接受所有弹框

func (*Page) Html added in v0.0.4

func (pg *Page) Html() (string, error)

func (*Page) Key added in v0.0.6

func (pg *Page) Key(keys ...string) error

func (*Page) KeyPress added in v0.0.6

func (pg *Page) KeyPress(keys ...string) error

func (*Page) KeyRelease added in v0.0.6

func (pg *Page) KeyRelease(keys ...string) error

func (*Page) KeyType added in v0.0.6

func (pg *Page) KeyType(keys ...string) error

func (*Page) MouseClick added in v0.0.4

func (pg *Page) MouseClick() error

func (*Page) MouseDown added in v0.0.4

func (pg *Page) MouseDown() error

func (*Page) MouseMiddleClick added in v0.0.4

func (pg *Page) MouseMiddleClick() error

func (*Page) MouseMoveTo added in v0.0.4

func (pg *Page) MouseMoveTo(x, y float64) error

func (*Page) MouseRightClick added in v0.0.4

func (pg *Page) MouseRightClick() error

func (*Page) MouseUp added in v0.0.4

func (pg *Page) MouseUp() error

func (*Page) Navigate added in v0.0.4

func (pg *Page) Navigate(url string) error

func (*Page) PDF added in v0.0.4

func (pg *Page) PDF() ([]byte, error)

PDF 生成页面PDF

func (*Page) RandWait added in v0.0.5

func (pg *Page) RandWait(msMin int, msMax int)

RandWait 随机等待

func (*Page) ResetTimeout added in v0.0.5

func (pg *Page) ResetTimeout()

func (*Page) Screenshot added in v0.0.4

func (pg *Page) Screenshot() ([]byte, error)

func (*Page) ScreenshotFullPage added in v0.0.4

func (pg *Page) ScreenshotFullPage() ([]byte, error)

Screenshot 截图

func (*Page) ScrollTo added in v0.0.4

func (pg *Page) ScrollTo(x, y float64) error

ScrollTo 滚动到指定位置

func (*Page) SetCookies added in v0.0.4

func (pg *Page) SetCookies(cookies map[string]string) error

func (*Page) SetPhoneViewport added in v0.0.4

func (pg *Page) SetPhoneViewport(width, height int) error

func (*Page) SetPrompt added in v0.0.4

func (pg *Page) SetPrompt(text string) error

func (*Page) SetUserAgent added in v0.0.4

func (pg *Page) SetUserAgent(ua string) error

func (*Page) SetUserAgentInfo added in v0.0.4

func (pg *Page) SetUserAgentInfo(ua string, platform string, acceptLanguage string) error

func (*Page) SetViewport added in v0.0.4

func (pg *Page) SetViewport(width, height int) error

SetViewport 设置视口大小

func (*Page) Title added in v0.0.4

func (pg *Page) Title() (string, error)

func (*Page) Url added in v0.0.4

func (pg *Page) Url() (string, error)

func (*Page) Wait added in v0.0.5

func (pg *Page) Wait(ms int, fn *func() bool)

Wait 等待回调函数函数返回true

func (*Page) WaitIdle added in v0.0.4

func (pg *Page) WaitIdle(ms *int) error

WaitIdle 等待页面空闲(无网络请求和JS执行)

func (*Page) WaitPageLoad added in v0.0.4

func (pg *Page) WaitPageLoad() error

WaitLoad 等待页面加载完成

type Position added in v0.0.4

type Position struct {
	X float64
	Y float64
}

type Rect added in v0.0.4

type Rect struct{ X, Y, Width, Height float64 }

type Resource added in v0.0.4

type Resource struct {
	Url          string
	Type         string
	Size         int
	MimeType     string
	LastModified string
	Success      bool
}

type WS

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

func (*WS) Close

func (ws *WS) Close(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*WS) Ping added in v0.0.3

func (ws *WS) Ping(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*WS) PingCount added in v0.0.3

func (ws *WS) PingCount(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*WS) Read

func (ws *WS) Read(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*WS) Write

func (ws *WS) Write(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

func (*WS) WriteMessage added in v0.0.3

func (ws *WS) WriteMessage(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value

Jump to

Keyboard shortcuts

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