Python Selenium binding with TOR browser Python Selenium binding with TOR browser selenium selenium

Python Selenium binding with TOR browser


A working example with Selenium and Tor on windows :

from selenium import webdriverfrom selenium.webdriver.firefox.firefox_profile import FirefoxProfilefrom selenium.webdriver.firefox.firefox_binary import FirefoxBinarybinary = FirefoxBinary(r"C:\Program Files (x86)\TorBrowser\Browser\firefox.exe")profile = FirefoxProfile(r"C:\Program Files (x86)\TorBrowser\Browser\TorBrowser\Data\Browser\profile.default")driver = webdriver.Firefox(profile, binary)driver.get("http://stackoverflow.com")driver.save_screenshot("screenshot.png")driver.quit()


Another simple solution is:Create a new profile in Firefox or Chrome,configure your browser to use Tor proxy (Set a SOCKS 5 proxy to address 127.0.0.1 port 9150), and then load that profile when you use webdriver.


Update selenium using:

pip install -U selenium

Then run your code, after starting TOR of course.This error was acknowledged and repaired.

P.S: Don't forget 'Sudo' if you are on Linux.