【问题标题】:Why ProxyServer not working on chromedp GO为什么 ProxyServer 不能在 chromedp GO 上运行
【发布时间】:2019-08-22 00:21:25
【问题描述】:

我想在 chromedp 上使用代理,但代理似乎不起作用,尝试 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。没有错误/警告

【问题讨论】:

    标签: go proxy google-chrome-headless


    【解决方案1】:

    试试这个:

    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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2013-09-05
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多