Last active
November 26, 2020 09:06
-
-
Save reuniware/5d32c65d4b93d1a977fdb8ea2207f1a0 to your computer and use it in GitHub Desktop.
Python + Tor on Windows (IP rotation + Chrome browsing)
This file contains hidden or 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
# Add C:\...\Tor Browser\Browser\TorBrowser\Tor to the current user's environment variables (Windows 10) | |
# Replace PATH_TO_CHROMEDRIVER by the one on your computer (you must download ChromeDriver) | |
from torrequest import TorRequest | |
from selenium import webdriver | |
import time | |
import requests | |
if __name__ == '__main__': | |
print('Python + TOR') | |
for i in range(0, 1000): | |
with TorRequest(proxy_port=9150, ctrl_port=9151, password=None) as tr: | |
resp = tr.get('http://www.ipecho.net/plain') | |
print(resp.text) | |
chrome_options = webdriver.ChromeOptions() | |
proxy = 'localhost:9150' | |
chrome_options.add_argument('--proxy-server=socks5://%s' % proxy) | |
driver = webdriver.Chrome('C:\PATH_TO_CHROMEDRIVER\chromedriver_win32\chromedriver.exe', chrome_options=chrome_options) | |
driver.get("http://www.ipecho.net/plain") | |
time.sleep(30) | |
driver.quit() | |
tr.reset_identity() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment