问题
I want to use proxy on chromedp, but proxy not seems to be working, tried chromedp.ProxyServer
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
chromedp.ProxyServer("http://username:password@proxyserver.com:31280")
chromedp.Run(ctx,
chromedp.Navigate("http://wtfismyip.com"),
chromedp.Sleep(3*time.Second),
chromedp.ActionFunc(func(ctxt context.Context) error {
_, _, contentRect, err := page.GetLayoutMetrics().Do(ctxt)
v := page.Viewport{
X: contentRect.X,
Y: contentRect.Y,
Width: contentRect.Width,
Height: contentRect.Height,
Scale: 1,
}
buf, err := page.CaptureScreenshot().WithClip(&v).Do(ctxt)
log.Printf("Write %v", "/tmp/ss.png")
ioutil.WriteFile("/tmp/ss.png", buf, 0644)
return err
}))
I am getting my public ipeven after using proxy. No error/warnings
回答1:
Try this:
o := append(chromedp.DefaultExecAllocatorOptions[:],
//... any options here
chromedp.ProxyServer("http://username:password@proxyserver.com:31280"),
)
cx, cancel := chromedp.NewExecAllocator(context.Background(), o...)
defer cancel()
ctx, cancel := chromedp.NewContext(cx)
defer cancel()
//... the rest of your code
来源:https://stackoverflow.com/questions/57412930/why-proxyserver-not-working-on-chromedp-go