Created
July 12, 2018 21:58
-
-
Save baatout/5d8b3628744dcea10b019b2ce9a48650 to your computer and use it in GitHub Desktop.
A part of the crawler tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 | |
for i in range(0, number_of_ip_rotations): | |
old_ip = ip | |
seconds = 0 | |
tor_handler.renew_connection() | |
# Loop until the 'new' IP address is different than the 'old' IP address, | |
# It may take the TOR network some time to effect a different IP address | |
while ip == old_ip: | |
time.sleep(wait_time) | |
seconds += wait_time | |
print('{} seconds elapsed awaiting a different IP address.'.format(seconds)) | |
# http://icanhazip.com/ is a site that returns your IP address | |
ip = tor_handler.open_url('http://icanhazip.com/') | |
print('My new IP: {}'.format(ip)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment