browsermobproxy

package module
v0.0.0-...-806115c Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 14 Imported by: 0

README

browsermobproxy-go

browsermobproxy for go

How too use it?

Create new server?

    //the path browsermob-proxy install
    Server =browsermobproxy.NewServer("/Users//bin/browsermob-proxy")
    Server.Start()

create proxy

proxy :=Server.CreateProxy(browsermobproxy.Params{"trustAllServers":"true"})

chromeCaps := chrome.Capabilities{
		Prefs:            imgCaps,
		Path:             "",
		Args: []string{
			//"--headless",
			"--start-maximized",
			"--window-size=1200x600",
			"--no-sandbox",
			"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
			"--disable-gpu",
			"--disable-impl-side-painting",
			"--disable-gpu-sandbox",
			"--disable-accelerated-2d-canvas",
			"--disable-accelerated-jpeg-decoding",
			"--test-type=ui",
		},
	}

add it to chrome

var caps selenium.Capabilities
chromeCaps.Args = append(spider.ChromeCaps.Args, fmt.Sprintf("--proxy-server=%s",p.Proxy))
caps.AddChrome(chromeCaps)
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 9515))

use newhar

options :=make(map[string]string)
	options["captureHeaders"] = "true"
	options["captureContent"] = "true"
	proxy.NewHar("loginform",options)
	wd.get("url")
	result :=proxy.Har()

v1.0 you can use 1、proxy 2、Har 3、NewHar 4、Blacklist 5、ResponseInterceptor 6、RequestInterceptor

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPClient = http.DefaultClient

Functions

func CheckPidRunning

func CheckPidRunning(serverName string) (string, error)

根据进程名判断进程是否运行

Types

type Client

type Client struct {
	Host  string `json:"host"`
	Port  int    `json:"port"`
	Proxy string `json:"proxy"`
}

func NewClient

func NewClient(urlStr string, param Params, options Params) *Client

func (*Client) Blacklist

func (c *Client) Blacklist(regexp string, statusCode int)

加入黑名单

func (*Client) ClearAllRewriteUrlRules

func (c *Client) ClearAllRewriteUrlRules() int

func (*Client) Close

func (c *Client) Close() int

关闭客户端

func (*Client) Har

func (c *Client) Har() *simplejson.Json

func (*Client) Headers

func (c *Client) Headers(headers map[string]string) int

func (*Client) NewHar

func (c *Client) NewHar(ref string, options map[string]string)

func (*Client) NewPage

func (c *Client) NewPage(ref, title string) int

new page

func (*Client) RequestInterceptor

func (c *Client) RequestInterceptor(js string) int

请求拦截

func (*Client) ResponseInterceptor

func (c *Client) ResponseInterceptor(js string) int

拦截请求内容

func (*Client) Retry

func (c *Client) Retry(count int) int

func (*Client) RewriteUrl

func (c *Client) RewriteUrl(match, replace string) int

func (*Client) Whitelist

func (c *Client) Whitelist(regexp string, statusCode int)

白名单

type Params

type Params map[string]string

type Server

type Server struct {
	Path    string      `json:"path"`
	Host    string      `json:"host"`
	Port    int         `json:"port"`
	Process *os.Process `json:"process"`
	Command string      `json:"command"`
	Url     string      `json:"url"`
}

func NewServer

func NewServer(path string) *Server

initialises a server object

func (*Server) CreateProxy

func (s *Server) CreateProxy(param Params) *Client

创建代理

func (*Server) Start

func (s *Server) Start()

启动

func (*Server) Stop

func (s *Server) Stop()

停止

Jump to

Keyboard shortcuts

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