go - 如何使用 chromedp 代理

标签 go proxy chromedp

我想截取亚马逊等网站(数千页)的屏幕截图。我尝试了一些代码,但在屏幕截图中出现了验证码或流量错误。所以我想用 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
        }))

也试过了,但没有用。

最佳答案

检查这个answer

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

关于go - 如何使用 chromedp 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57460884/

相关文章:

java - 如何在go中读取二进制数据?(智能卡)将代码转换为Java

google-chrome - 如何使用 chromedp 获取 HTTP 响应主体?

arrays - 字符串如何存储在 GO 数组中?

android - Chrome 正在绕过我的 Google Nexus 5 上的代理设置

nginx - 使用 proxy_pass 配置 Nginx 的两个位置

asp.net - 如何将 Microsoft 身份验证重定向到应用程序代理 URL 而不是内部 URL

go - 无法获取当前窗口标题

go - 我在 golang 中错误地使用了 channel 吗?

go - 在 Golang 中将 MD5 转换为十进制的最佳方法?