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

Allow Proxy Middleware Configuration for Specific Spiders #74

Open
SergeyKapshuchenko opened this issue Jan 28, 2025 · 2 comments
Open

Comments

@SergeyKapshuchenko
Copy link

Good day !

I would like to know if it's possible to configure the proxy middleware in a way that it applies only to specific spiders instead of all spiders in a Scrapy project.

For example, I want to have a toggle or setting for each spider that decides whether proxies should be used or not. Is there a recommended way to achieve this using the Scrapy framework?

Example Use Case:
Spider A should use proxies.
Spider B should not use proxies.
Would it be possible to configure the middleware dynamically per spider or implement logic to check this toggle and enable/disable the middleware accordingly? If yes, could you provide guidance or examples?

Thank you!

@devfox-se
Copy link

devfox-se commented Feb 4, 2025

Yes you can simply keep this middleware off for any spider that you dont need it by overriding settings on sniper creation. You can tailor any setting for a specific spider using update_settings classmethod

Best practice for middlewares is that it should have an ENABLED flag/value which users could use to enable/disable the middleware but this one does not have such parameter, instead you can clear the list of proxies and the middleware will deactivate itself automatically based on its initialization logic

@classmethod
def update_settings(cls, settings):
    super().update_settings(settings)
    settings["ROTATING_PROXY_LIST"].clear()

@SergeyKapshuchenko
Copy link
Author

Thanks !

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

2 participants