req
req copied to clipboard
How do I use a different proxy for each request
How do I use a different proxy for each request
How do I use a different proxy for each request
I think it's not possible with goroutines. So I just created a channel of req.Client and use it in the code like this
cl := <-clients
defer func() {clients <- cl}()
cl.SetProxyUrl(...)
*other code*
Proxy is a client-level only setting, but you can use some hook (e.g. OnBeforeRequest) to change proxy for each request.
The exampoe here may inspire you: https://req.cool/docs/examples/easily-write-crawlers-with-req/#automatically-change-ip-when-request-fails-set-proxy