Skip to content

Instantly share code, notes, and snippets.

from adder import add
z = add(4.0, 6.0)
@baatout
baatout / ip_renewal.py
Created July 12, 2018 21:58
A part of the crawler tutorial
...
wait_time = 2
number_of_ip_rotations = 3
tor_handler = TorHandler()
ip = tor_handler.open_url('http://icanhazip.com/')
print('My first IP: {}'.format(ip))
# Cycle through the specified number of IP addresses via TOR
@baatout
baatout / tor_handler.py
Created July 12, 2018 22:01
A part from the crawler tutorial
from urllib.request import ProxyHandler, build_opener, install_opener, Request, urlopen
from stem import Signal
from stem.control import Controller
class TorHandler:
def __init__(self):
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'}