Skip to main content

ProxyConfiguration

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.

Index

Methods

__init__

  • __init__(*, proxy_urls, new_url_function, tiered_proxy_urls): None
  • A default constructor.

    Exactly one of proxy_urls, tiered_proxy_urls or new_url_function must be specified.


    Parameters

    • optionalkeyword-onlyproxy_urls: list[str | None] | None = None

      A list of URLs of proxies that will be rotated in a round-robin fashion

    • optionalkeyword-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.

    • optionalkeyword-onlytiered_proxy_urls: list[list[str | None]] | 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

new_proxy_info

  • async new_proxy_info(*, session_id, request, proxy_tier): ProxyInfo | None
  • 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

    • optionalkeyword-onlysession_id: str | None
    • optionalkeyword-onlyrequest: Request | None
    • optionalkeyword-onlyproxy_tier: int | None

    Returns ProxyInfo | None

new_url

  • async new_url(*, session_id, request, proxy_tier): str | None
  • 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

    • optionalkeyword-onlysession_id: str | None = None
    • optionalkeyword-onlyrequest: Request | None = None
    • optionalkeyword-onlyproxy_tier: int | None = None

    Returns str | None

Page Options