Skip to main content

IP Rotator for Scrapy via Tor

Project description


The purpose of this module is to allow rotation of IPs to Scrapy via Tor.


Simple way to install, via pip:

pip install scrapy-tor-proxy-rotation

Configuring Tor

You need to configure Tor. First, install it:

sudo apt-get install tor

Stop its execution to perform configuration:

sudo service tor stop

Open your configuration file as root, available at /etc/tor/torrc, for example using nano:

sudo nano /etc/tor/torrc

Insert the lines below and save:

ControlPort 9051
CookieAuthentication 0

Restart Tor:

sudo service tor start

You can check your machine's IP and compare it with Tor's by doing the following:

  • To see your machine's IP:
  • To see Tor's IP:
    torify curl   

Tor proxies are not supported by Scrapy. To get around this problem, it is necessary to use an intermediary, in this case Privoxy.

The Tor proxy server is by default at

Installing and configuring Privoxy:

  • Install:
    sudo apt install privoxy
  • Stop its execution:
    sudo service privoxy stop
  • Configure it to use TOr, open its configuration file:
    sudo nano /etc/privoxy/config
  • Add the following lines:
    forward-socks5t / .
  • Start it up:
    service privoxy start

By default, privoxy will run at the address


torify curl
curl -x

The IP shown in the two steps above must be the same.

How to use

After you have made these settings, you can now integrate Tor with Scrapy.

  • Configure the middleware in your project's configuration file (

        'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
        'tor_ip_rotator.middlewares.TorProxyMiddleware': 100
  • Enable the use of extension:

    TOR_IPROTATOR_CHANGE_AFTER = #number of requests made on the same Tor's IP address

By default, an IP can be reused after 10 other uses. This value can be changed by the variable TOR_IPROTATOR_ALLOW_REUSE_IP_AFTER, as below:

TOR_IPROTATOR_ALLOW_REUSE_IP_AFTER = 0 #another integer value

A number too large for TOR_IPROTATOR_ALLOW_REUSE_IP_AFTER may make it slower to retrieve a new IP for use or not find one at all. If the value is 0, there will be no record of used IPs.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy-tor-proxy-rotation-0.0.4.tar.gz (5.7 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page