Why ProxyServer not working on chromedp GO

元气小坏坏 提交于 2019-12-25 00:52:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!