我想在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。无错误/警告
试试这个:
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