goproxychromedp

How to us proxy with chromedp


I want to take screenshot of (thousands of pages) of website like Amazon. I tried some code but getting captcha or traffic error in screenshot. So I want to add proxy with 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
        }))

Tried this as well but not working.


Solution

  • Check this answer

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