Modules and packages in Python for connecting to the Tor network
In this section, you'll learn how to extract information from the Tor network with the stem
Python module. Let's start by learning how to connect to the requests
and PySocks
Python modules.
Connecting to the Tor network from Python
Python gives us some alternatives for connecting to the Tor network in a programmatic way:
- Stem is a library written in Python that's used to programmatically control a Tor instance and get information about relays. You can find out more at https://stem.torproject.org and https://pypi.org/project/stem/.
- Torrequests is basically a wrapper for the
stem
andrequests
libraries: https://github.com/erdiaker/torrequest. - The other alternative is to use the
requests
andsocks5
combination.
We'll start by analyzing the requests
and socks5
combination. Since Tor requires a SOCKS proxy for communication, we can use the Python requests
library in combination...