我开始和科利打交道。我正在尝试为每个请求设置一个代理。但并不是所有的请求都通过代理
它应该可以工作,https://github.com/gocolly/colly/blob/master/request.go#L52
我已经将此代码添加到我的代码中。但是请求像以前一样没有代理。
c.OnRequest(func(r *colly.Request) {
r.ProxyURL = "..."
}也许我没有正确理解这应该是如何工作的
发布于 2019-09-02 17:38:42
您是否尝试过在收集器上设置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
}https://stackoverflow.com/questions/57754483
复制相似问题