Skip to content
Nefo

Scrapy

How to Use Residential Proxies with Scrapy

Attach Nefo residential proxies to Scrapy requests through the built-in HttpProxyMiddleware, with rotating IPs for wide crawls and sticky sessions for paginated sections.

Before you start

Nefo offers residential proxies across 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic uses your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).

Scrapy ships with HttpProxyMiddleware enabled by default, so you only need to supply the proxy URL per request.

  • Python 3.9+ with Scrapy installed
  • A Nefo account with prepaid bandwidth
  • A username/password from /dashboard/generator
  • HttpProxyMiddleware enabled (default)
  • AUTOTHROTTLE and a sane DOWNLOAD_DELAY configured

Scrapy proxy in request meta

Attach the proxy in your spider's requests:

The username token USERNAME-country-us requests a rotating US residential IP. Change the country code, or add state, city, or ASN tokens, to steer exits. For SOCKS5, install scrapy-rotating-proxies or a SOCKS-capable middleware and point at port 11000.

shell
import scrapy


class ExampleSpider(scrapy.Spider):
    name = 'example'
    urls = ['https://api.ipify.org']

    def start_requests(self):
        proxy = 'http://USERNAME-country-us:[email protected]:9000'
        for url in self.urls:
            yield scrapy.Request(url, meta={'proxy': proxy}, callback=self.parse)

    def parse(self, response):
        self.logger.info(response.text)

Scrapy rotating vs sticky proxy sessions

Rotating sessions issue a new residential IP per request on HTTP port 9000, which pairs naturally with Scrapy's concurrent scheduler for wide crawls.

Sticky sessions hold one IP from 1 minute up to 24 hours on HTTP port 10000. Use a token like USERNAME-country-us-session-cat12-lifetime-20 to keep the same IP while paginating a section, then rotate the session id for the next block.

Geo-targeting and polite crawling in Scrapy

Targeting is set through username tokens: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username changes, so a single spider can crawl multiple regions.

Crawl lawfully, honor robots directives and site terms, and keep AUTOTHROTTLE on to stay within reasonable rates.

Frequently asked questions

No. Scrapy's built-in HttpProxyMiddleware reads meta['proxy'], so setting it per request is enough for HTTP proxies. Make sure the middleware has not been disabled in your settings.

Start with 5 GB. Keep what you don't use.

Residential bandwidth from $0.53/GB that never expires. Card, PayPal, Apple Pay, Google Pay, Alipay and crypto.