为了账号安全,请及时绑定邮箱和手机立即绑定

GoColly 为每个请求设置代理

GoColly 为每个请求设置代理

Go
慕田峪4524236 2023-07-17 16:41:53
我开始对付科利。我正在尝试为每个请求设置代理。但所有请求都不经过代理它应该有效 https://github.com/gocolly/colly/blob/master/request.go#L52我已将其添加到我的代码中。但请求像以前一样没有代理c.OnRequest(func(r *colly.Request) {    r.ProxyURL = "..."    }也许我没有正确理解它应该如何工作
查看完整描述

1 回答

?
qq_遁去的一_1

TA贡献1725条经验 获得超7个赞

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

}


查看完整回答
反对 回复 2023-07-17
  • 1 回答
  • 0 关注
  • 100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信