【问题标题】:How to us proxy with chromedp如何使用 chromedp 进行代理
【发布时间】:2019-12-19 00:21:56
【问题描述】:

我想截取亚马逊等网站的(数千页)屏幕截图。我尝试了一些代码,但在屏幕截图中出现验证码或流量错误。所以我想用chromedp添加代理。

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

也试过了,但没用。

【问题讨论】:

  • 避免验证码并不是那么简单,因为验证码是为了防止像您这样的机器人。你为什么要这么做?
  • @kabanek 我不明白这一点。所以我只需要使用 chromedp 传递代理。那么有没有办法用chromedp添加代理
  • 您对添加代理有什么疑问?
  • @Adrian 如何在 golang 中使用带有 chromedp 的代理???
  • 使用chromedp.ProxyServer,你已经在你的问题中,所以不清楚你在问什么。你能展示你的代码吗?

标签: go proxy chromedp


【解决方案1】:

查看answer

o := append(chromedp.DefaultExecAllocatorOptions[:],
  //... any options here
  chromedp.ProxyServer("http://username:password@proxyserver.com:31280"), 
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-25
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2021-11-24
    • 1970-01-01
    相关资源
    最近更新 更多