cdputil

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

cdputil

chromedp扩展

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookieConverter added in v1.0.4

func CookieConverter(cookies []*network.Cookie) []*http.Cookie

CookieConverter []*network.Cookie转为[]*http.Cookie

func GetCookies added in v1.0.5

func GetCookies(ctx context.Context, domain string) ([]*http.Cookie, error)

GetCookies 获取特定域名的Cookies

func GetPostData added in v1.0.9

func GetPostData(r *network.Request) string

GetPostData 获取postData

func HeaderConverter

func HeaderConverter(header network.Headers) []*fetch.HeaderEntry

HeaderConverter network.Headers转为[]*fetch.HeaderEntry

func HeaderFromMap added in v1.0.5

func HeaderFromMap(header map[string]string) network.Headers

HeaderFromMap map[string]string转为network.Headers

func Request added in v1.0.5

func Request(method RequestMethod, urlStr, params string, headers map[string]string, tag *Tag, baseUrl string) (string, error)

Request 请求

func RequestRetry added in v1.0.5

func RequestRetry(retryCount int, method RequestMethod, urlStr, params string, headers map[string]string, tag *Tag, baseUrl string) (string, error)

RequestRetry 带重试请求

Types

type BrowserInfo added in v1.0.3

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

BrowserInfo 浏览器程序信息

func GetBrowserInfo added in v1.0.3

func GetBrowserInfo() *BrowserInfo

GetBrowserInfo 线程安全的获取浏览器程序信息单例

func (*BrowserInfo) WithHeadless added in v1.0.3

func (b *BrowserInfo) WithHeadless(headless bool) *BrowserInfo

WithHeadless 设置是否隐藏浏览器窗口, 默认为false

func (*BrowserInfo) WithName added in v1.0.3

func (b *BrowserInfo) WithName(name string) *BrowserInfo

WithName 设置浏览器名称, 默认为chrome.exe

func (*BrowserInfo) WithPort added in v1.0.3

func (b *BrowserInfo) WithPort(port uint) *BrowserInfo

WithPort 设置浏览器CDP端口, 默认为9222

func (*BrowserInfo) WithUrl added in v1.0.3

func (b *BrowserInfo) WithUrl(url string) *BrowserInfo

WithUrl 设置浏览器启动地址, 默认为$ProgramFiles (x86)\\Google\\Chrome\\Application\\chrome.exe

func (*BrowserInfo) WithWindowHeight added in v1.0.3

func (b *BrowserInfo) WithWindowHeight(height uint) *BrowserInfo

WithWindowHeight 设置浏览器窗口默认高度, 默认为0

func (*BrowserInfo) WithWindowWidth added in v1.0.3

func (b *BrowserInfo) WithWindowWidth(width uint) *BrowserInfo

WithWindowWidth 设置浏览器窗口默认宽度, 默认为0,

type RequestMethod added in v1.0.5

type RequestMethod string
const (
	RequestMethodGet     RequestMethod = "GET"
	RequestMethodPost    RequestMethod = "POST"
	RequestMethodPut     RequestMethod = "PUT"
	RequestMethodDelete  RequestMethod = "DELETE"
	RequestMethodHead    RequestMethod = "HEAD"
	RequestMethodOptions RequestMethod = "OPTIONS"
	RequestMethodTrace   RequestMethod = "TRACE"
	RequestMethodConnect RequestMethod = "CONNECT"
)

func (RequestMethod) HasBody added in v1.0.5

func (rm RequestMethod) HasBody() bool

HasBody 是否有body

func (RequestMethod) String added in v1.0.9

func (rm RequestMethod) String() string

String 转为字符串

type RequestTask

type RequestTask struct {
	RequestId        string           //请求ID
	DocumentUrl      string           //文档地址
	Request          *network.Request //请求
	RequestStartTime time.Time        //请求时间

	Type network.ResourceType //类型

	IsFinished   bool              //是否已经完成
	Response     *network.Response //响应
	ResponseBody string            //响应体
	ErrorText    string            //错误原因

	HasRewrite    bool                         //是否修改过
	RewriteParams *fetch.ContinueRequestParams //重写参数
}

func (*RequestTask) IsTimeout added in v1.0.4

func (rt *RequestTask) IsTimeout(timeout time.Duration) bool

IsTimeout 是否超时

func (*RequestTask) Success

func (rt *RequestTask) Success() bool

Success 是否成功

type Tag

type Tag struct {
	IsWaitCurrentRequestTasksFinished bool          //是否等待当前所有的请求任务完成(或超时), 默认为true
	RequestTimeout                    time.Duration //请求超时时间,默认1min
	RequestPausedCallback             func(rp *fetch.EventRequestPaused) *fetch.ContinueRequestParams
	RequestTaskValidTypesMap          map[network.ResourceType]bool // 需要保存的请求任务类型,如果为空,则全部保存
	// contains filtered or unexported fields
}

Tag 浏览器标签

func NewTag

func NewTag(timeout time.Duration) (*Tag, error)

NewTag 创建一个Tag

func (*Tag) Cancel

func (t *Tag) Cancel()

Cancel 关闭Tag

func (*Tag) GetRequestTask added in v1.0.2

func (t *Tag) GetRequestTask(requestId string) *RequestTask

GetRequestTask 获取请求任务,可为nil

func (*Tag) RangeRequestTask added in v1.0.1

func (t *Tag) RangeRequestTask(f func(key string, rt *RequestTask) bool)

RangeRequestTask 遍历请求任务

func (*Tag) Run

func (t *Tag) Run(actions ...chromedp.Action) error

func (*Tag) RunMain

func (t *Tag) RunMain(actions ...chromedp.Action) error

func (*Tag) WaitRequestTaskFinish added in v1.0.2

func (t *Tag) WaitRequestTaskFinish(requestIdPts ...*string) chromedp.ActionFunc

WaitRequestTaskFinish 等待请求任务完成(不计算请求超时),requestIdPts为requestId的指针地址

Jump to

Keyboard shortcuts

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