GoColly 为每个请求设置代理

我开始对付科利。我正在尝试为每个请求设置代理。但所有请求都不经过代理

它应该有效 https://github.com/gocolly/colly/blob/master/request.go#L52

我已将其添加到我的代码中。但请求像以前一样没有代理

c.OnRequest(func(r *colly.Request) { 
  r.ProxyURL = "..." 
  }

也许我没有正确理解它应该如何工作


慕田峪4524236
浏览 104回答 1
1回答

qq_遁去的一_1

ProxyURL您是否尝试过在收集器上设置它,而不是在回调函数中设置?// SetProxy sets a proxy for the collector. This method overrides the previously// used http.Transport if the type of the transport is not http.RoundTripper.// The proxy type is determined by the URL scheme. "http"// and "socks5" are supported. If the scheme is empty,// "http" is assumed.func (c *Collector) SetProxy(proxyURL string) error {    proxyParsed, err := url.Parse(proxyURL)    if err != nil {        return err    }    c.SetProxyFunc(http.ProxyURL(proxyParsed))    return nil}
打开App,查看更多内容
随时随地看视频慕课网APP