Skip to main content

Scrapy Tor Proxy Rotation

This module allows Scrapy to rotate Tor IPs.

Install

Simple install, via pip:

pip install scrapy-tor-proxy-rotation

Config Tor

To configure Tor. First, install :

sudo apt-get install tor

Stop its execution to make configurations:

sudo service tor stop

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

sudo nano /etc/tor/torrc

Place the lines below and save:

ControlPort 9051
CookieAuthentication 0

Restart Tor:

sudo service tor start

It is possible to verify the IP of your machine and compare it as Tor in the following way:

  • To see your IP:
    curl http://icanhazip.com/
    
  • To see the ip of Tor:
    torify curl http://icanhazip.com/   
    

For Scrapy it is necessary to use an intermediary, in this case or Privoxy.

Tor Default Proxy Server: 127.0.0.1:9050

Install and Config Privoxy:

  • Install:
    sudo apt install privoxy
    
  • Stop the service:
    sudo service privoxy stop
    
  • Open the config file:
    sudo nano /etc/privoxy/config
    
  • Add the following lines:
    forward-socks5t / 127.0.0.1:9050 .
    
  • Start the service:
    service privoxy start
    

Test:

torify curl http://icanhazip.com/
curl -x 127.0.0.1:8118 http://icanhazip.com/

Use

After performing these configurations, it is possible to integrate Tor with Scrapy.

  • Configure the middleware in your settings file (settings.py):

    DOWNLOADER_MIDDLEWARES = {
        ...,
        'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
        'tor_ip_rotator.middlewares.TorProxyMiddleware': 100
    }
    
  • Add those in your custom_settings in your spider or in (settings.py) if you want to use them on all spiders from the project:

    TOR_IPROTATOR_ENABLED = True
    TOR_IPROTATOR_CHANGE_AFTER = #número de requisições feitas em um mesmo endereço IP
    

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

TOR_IPROTATOR_ALLOW_REUSE_IP_AFTER = #

A large number can also make it slower to retrieve a new IP to use or find. If the value is 0, there will be no record of used IPs.

Metadata

Release files for scrapy-tor-proxy-rotator 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapy-tor-proxy-rotator 0.0.2
File Size Uploaded Provenance Actions
scrapy-tor-proxy-rotator-0.0.2.tar.gz 4.6 kB Without provenance Details for scrapy-tor-proxy-rotator-0.0.2.tar.gz

Release files / scrapy-tor-proxy-rotator-0.0.2.tar.gz

Download URL scrapy-tor-proxy-rotator-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
572ecb1df7ea05685ae012c82325a7e237274cd17b244219652b4f39d3de49c7
BLAKE2b-256 checksum
How to use checksums
6e6afa50fcab6bf4dbebf905cfc6b07b872acdd7ff938882e14ca3a94e539227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Security for scrapy-tor-proxy-rotator 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page