ProxyConfiguration
Index
Constructors
Methods
Constructors
__init__
Initialize a proxy configuration object.
Exactly one of
proxy_urls
,tiered_proxy_urls
ornew_url_function
must be specified.Parameters
keyword-onlyproxy_urls: list[str] | None = None
A list of URLs of proxies that will be rotated in a round-robin fashion
keyword-onlynew_url_function: _NewUrlFunction | None = None
A function that returns a proxy URL for a given Request. This provides full control over the proxy selection mechanism.
keyword-onlytiered_proxy_urls: list[list[str]] | None = None
A list of URL tiers (where a tier is a list of proxy URLs). Crawlers will automatically try to use the lowest tier (smallest index) where blocking does not happen. The proxy URLs in the selected tier will be rotated in a round-robin fashion.
Returns None
Methods
new_proxy_info
Return a new ProxyInfo object.
If called repeatedly with the same request, it is assumed that the request is being retried. If a previously used session ID is received, it will return the same proxy url.
Parameters
session_id: str | None
request: Request | None
proxy_tier: int | None
Returns ProxyInfo | None
new_url
Return a new proxy url.
If called repeatedly with the same request, it is assumed that the request is being retried. If a previously used session ID is received, it will return the same proxy url.
Parameters
session_id: str | None = None
request: Request | None = None
proxy_tier: int | None = None
Returns str | None
Configures connection to a proxy server with the provided options.
Proxy servers are used to prevent target websites from blocking your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures them to use the selected proxies for all connections. You can get information about the currently used proxy by inspecting the ProxyInfo property in your crawler's page function. There, you can inspect the proxy's URL and other attributes.
If you want to use your own proxies, use the ProxyConfigurationOptions.proxyUrls option. Your list of proxy URLs will be rotated by the configuration if this option is provided.