Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use a different proxy for each request #388

Open
shiqiangz-git opened this issue Sep 23, 2024 · 2 comments
Open

How do I use a different proxy for each request #388

shiqiangz-git opened this issue Sep 23, 2024 · 2 comments

Comments

@shiqiangz-git
Copy link

shiqiangz-git commented Sep 23, 2024

How do I use a different proxy for each request

@shiqiangz-git shiqiangz-git changed the title 程序运行一段时间直接退出如何解决已经使用了demo的全局捕获异常 How do I use a different proxy for each request Sep 25, 2024
@Deferede
Copy link

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*

@imroc
Copy link
Owner

imroc commented Oct 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants