M
M
Mikhail2017-12-09 11:40:25
Python
Mikhail, 2017-12-09 11:40:25

How to set up Tor to work in Python?

Operating system - Windows
I need to be able to make requests with a proxy from the torus
Here is the code itself:

import requests

def get_tor_session():
    session = requests.session()
    # Tor uses the 9050 port as the default socks port
    session.proxies = {'http':  'socks5://127.0.0.1:9051',
                       'https': 'socks5://127.0.0.1:9051'}
    return session

# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP

# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)

But I don't know how to configure tor. How to set a password, port, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2017-12-09
@TheMaxai

Gorgeous instructions - https://jarroba.com/anonymous-scraping-by-tor-network/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question