Crawlee Proxy Setup for Rotating Proxies

Configure Crawlee to use RotatingProxy's gateway for HTTP and SOCKS5 connections. The proxy settings are managed through Crawlee's ProxyConfiguration class, which handles authentication, rotation, and session persistence.

Key points
  • Use the ProxyConfiguration class to inject proxy settings into all crawler requests.
  • Build the proxy username with options like net.res, cc.us, and sid for targeting and sticky sessions.
  • Port 7070 for HTTP/HTTPS and 7071 for SOCKS5, both supported by Crawlee.
  • Verify your exit IP with a simple request to ipify.org to confirm the proxy is working.

Crawlee Proxy Setup Overview

Integrating RotatingProxy with Crawlee involves creating a ProxyConfiguration object that instructs Crawlee's HTTP clients to route all requests through the gateway. This is the central place where you define your proxy server, authentication, and rotation behavior. Crawlee supports both HTTP and SOCKS5 proxy protocols, making it compatible with our gateway on ports 7070 and 7071. This setup is essential for tasks like web scraping, price monitoring, and rank tracking where IP rotation helps avoid blocks.

Where Proxy Settings Live in Crawlee

Proxy settings in Crawlee are centralized in the ProxyConfiguration class, which is part of the crawler's launch configuration. You create an instance of this class, provide the proxy server details, and then pass it when launching a CheerioCrawler, PlaywrightCrawler, or any other crawler type. This configuration is then automatically applied to every request the crawler makes, removing the need to manually set proxies on individual requests. It works smooth with Crawlee's built-in session and request queue management.

HTTP and HTTPS Setup on Port 7070

To use the HTTP proxy port (7070), you construct a proxy URL string that includes authentication and targeting options. The general format is http://USERNAME:PASSWORD@gw.rotatingproxy.cc:7070, where the username contains your proxy user login and any options. Here is a complete example for a CheerioCrawler that uses a rotating residential IP from the United States.

import { CheerioCrawler, ProxyConfiguration } from 'crawlee';

const proxyConfiguration = new ProxyConfiguration({
    proxyUrls: [
        'http://USERNAME_net.res_cc.us:PASSWORD@gw.rotatingproxy.cc:7070'
    ]
});

const crawler = new CheerioCrawler({
    proxyConfiguration,
    async requestHandler({ request, $ }) {
        // Your parsing logic here
        console.log($('title').text());
    },
});

await crawler.run(['https://example.com']);

For HTTPS requests (like CONNECT tunneling to port 443), the same proxy URL and port 7070 are used. Crawlee handles the tunnel setup automatically. If you need to target a specific city, add the city option, for example, USERNAME_net.res_cc.us_city.new-york. This is useful for localization testing or real estate data collection from specific markets.

SOCKS5 Setup on Port 7071

Crawlee also supports SOCKS5 proxies, which you can use by connecting to port 7071. The setup is identical to the HTTP proxy, except you change the protocol in the proxy URL to socks5://. SOCKS5 can be beneficial in certain network environments, though for most web scraping tasks, the HTTP proxy on port 7070 is sufficient. Here is how to configure it.

const proxyConfiguration = new ProxyConfiguration({
    proxyUrls: [
        'socks5://USERNAME_net.mob_cc.de:PASSWORD@gw.rotatingproxy.cc:7071'
    ]
});

Both HTTP and SOCKS5 proxies from our gateway provide the same level of anonymity and support the same targeting options. For a more thorough look, check our guide on HTTP vs SOCKS5 proxies.

Passing Targeting and Session Options in the Username

All geo-targeting and session control is done through the username field using an underscore-separated syntax. The proxy user's login comes first, followed by key.value options. For example, to use a sticky session (the same IP for a period) from a mobile network in Germany, you would build a username like USERNAME_net.mob_cc.de_sid.abc123_ttl.30. The sid (session ID) can be any 6 to 16 character string you choose, and ttl sets the sticky duration in minutes (1-120).

This method is perfect for managing sessions in scrapers where you need to maintain login state or cookies across multiple requests to the same site, such as when scraping LinkedIn or Instagram. Without a sid, each new connection gets a fresh IP from the chosen location, which is the default rotating behavior. You can find all supported options in our username options documentation.

Verifying the Exit IP and Location

After setting up the proxy, it's good practice to verify that your traffic is exiting from the expected IP and location. You can do this by making a test request to a service that returns your IP address. Within your Crawlee request handler, you can send a request to https://api.ipify.org?format=json or https://ipinfo.io/json. Here's a simple verification snippet.

async requestHandler({ request, sendRequest }) {
    const testResponse = await sendRequest({
        url: 'https://api.ipify.org?format=json',
    });
    console.log('Exit IP:', testResponse.body.ip);
    // Continue with your main scraping logic
}

Confirming the IP matches the country you targeted (e.g., cc.us) ensures your configuration is correct. For more tools, see our page on checking the exit IP and location.

Fixing Common Proxy Errors in Crawlee

Several common errors can occur when connecting through a proxy. A 407 Proxy Authentication Required error means the username or password is wrong or malformed. Double-check that the full proxy URL is correctly assembled, with no missing underscores or typos. Our error 407 guide has more details.

Timeouts can happen if the target site is slow or if your network latency is high. Increase the requestHandlerTimeoutSecs in your crawler configuration and consider using a closer geographic location. For general advice, see proxy timeouts and slow responses.

TLS/SSL errors sometimes appear if there's an issue with the CONNECT tunnel. Make sure you are using port 7070 for HTTPS traffic. Crawlee's HTTP client typically handles TLS negotiation through the proxy smooth. If problems persist, test with a plain HTTP site first to isolate the issue.

Tips for Running Crawlee at Scale with RotatingProxy

For large-scale scraping, efficient proxy use is key. First, understand your concurrency limit (up to 1,000 concurrent connections per account). Distribute your workload across multiple proxy users, each with its own login, to organize traffic and apply individual monthly GB caps.

Use different session IDs (sid) for separate crawling threads or tasks that require independent IPs. This allows you to maintain multiple sticky sessions in parallel, which is useful for market research across many sites. Monitor your traffic usage to stay within budget; the pay-as-you-go model means costs are directly tied to data transfer. Implement caching and request deduplication to reduce proxy traffic costs.

Finally, always follow web scraping best practices: respect robots.txt, implement polite rate limiting, and use retries with exponential backoff. Our proxies are designed for lawful data collection, such as for academic research or open government data collection.

Connecting to Specific Websites and Platforms

The principles here apply to scraping any website. For platform-specific nuances, refer to our dedicated integration pages. For example, when scraping Google search, you may need to adjust request headers and use residential IPs. For Amazon, consider using session IDs to mimic a real user session. Crawlee's flexibility combined with RotatingProxy's targeting makes it a powerful tool for ecommerce data gathering and news monitoring.

Advanced Configuration with ProxyConfiguration

The ProxyConfiguration class offers advanced features like custom proxy URL rotation functions and the ability to assign specific proxies to specific requests. You can generate an array of proxy URLs with different session IDs for a simple round-robin effect, or even integrate with our API to fetch fresh proxy endpoints dynamically. Check the current Crawlee docs for the latest methods and properties, as the library evolves. This advanced control is key for planning concurrency for crawlers in production environments.

Questions

Can I use RotatingProxy with PlaywrightCrawler in Crawlee?

Yes, absolutely. The ProxyConfiguration works identically with PlaywrightCrawler. Pass the proxyConfiguration object when launching the crawler, and Playwright will route its browser traffic through the proxy. This is ideal for scraping JavaScript-heavy sites.

How do I switch between different proxy networks (e.g., residential to mobile) in the same crawler?

You specify the network in the username with the `net` option (e.g., `net.mob`). To use different networks, you would create separate proxy URLs with different usernames and configure the ProxyConfiguration to use them, perhaps by rotating through an array of URLs.

My crawler is getting blocked even with proxies. What should I do?

IP rotation is one part of avoiding blocks. Also ensure you are using realistic request headers, managing request rates politely, and potentially using headless browsers with Playwright to mimic human behavior. Review our guide on how to avoid getting blocked while scraping politely.

Does Crawlee handle proxy authentication for WebSocket connections in Playwright?

Playwright's proxy configuration, as used by PlaywrightCrawler, typically handles all browser traffic, including WebSockets, when set up via the proxy server argument. Ensure you are using the correct proxy URL format with authentication included.

How can I estimate how much proxy traffic my Crawlee project will use?

Monitor a small sample run and calculate the average data per request. Then multiply by your total expected requests. Use our traffic calculator tool to estimate costs. Remember, traffic is the sum of upload and download bytes.

What happens if my balance runs out during a long Crawlee job?

Traffic will stop, and requests will fail as the proxy gateway denies connections. You should monitor your balance via the API or dashboard and implement alerts. Top up your balance to resume. Read about what happens when the balance runs out.

Start with one top-up, use any network

Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.