为什么ProxyServer在chromedp GO上不起作用 [英] Why ProxyServer not working on chromedp GO

查看:91
本文介绍了为什么ProxyServer在chromedp GO上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在chromedp上使用代理,但代理似乎不起作用,尝试chromedp.ProxyServer

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
        }))

使用代理后,我获得了公共IPeven.没有错误/警告

I am getting my public ipeven after using proxy. No error/warnings

推荐答案

尝试一下:

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

这篇关于为什么ProxyServer在chromedp GO上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆