req
req copied to clipboard
关于重试设置代理
能第一次执行的时候也加上代理吗,这段代码好像只能触发重试才能触发代理
var crawlerClient = NewAutoChangeProxyClient()
func NewAutoChangeProxyClient() *req.Client {
client := req.C()
client.SetTimeout(5 * time.Second).
EnableDumpEachRequest().
SetCommonRetryCount(len(proxies)).
SetCommonRetryCondition(func(resp *req.Response, err error) bool {
return err != nil || resp.StatusCode == 403
}).
SetCommonRetryHook(func(resp *req.Response, err error) {
c := client.Clone().SetProxyURL(getProxuyUrl()) // Create a client with proxy
resp.Request.SetClient(c) // Change the client of request dynamically.
})
return client
}