dsadasd12132 2019-08-08 12:45
浏览 277
已采纳

为什么ProxyServer无法在chromedp GO上运行

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条回答 默认 最新

  • doudongdang4483 2019-08-21 16:21
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程