2

When I try opening Tor with selenium I get an error when tor opens saying "Tor failed to start." The only other post online with a similar problem that I found is: Selenium error

I also have geckodriver on my machine already.

My code looks like the following:

from selenium import webdriver    
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

    binary = FirefoxBinary(r"D:\Tor Browser\Browser\firefox.exe")
    profile = FirefoxProfile(r"D:\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', '127.0.0.1')
    profile.set_preference('network.proxy.socks_port', 9150)
    profile.set_preference('network.proxy.socks_remote_dns', 'False')
    driver = webdriver.Firefox(profile, binary)

enter image description here

Pedro Lopes
  • 479
  • 2
  • 9
  • 20

1 Answers1

2

TO open tor you can use :

https://github.com/webfp/tor-browser-selenium

Steps:

First goto tor browser and type about:profiles :

enter image description here

THen open Tor Browser\Browser\TorBrowser\Tor folder :

There you can see a tor.exe file double click that :

enter image description here

Then run below code

from tbselenium.tbdriver import TorBrowserDriver
import time
driver= TorBrowserDriver(executable_path=r"C:\Users\prave\Downloads\travelBA\geckodriver.exe", tbb_fx_binary_path=r'C:\Users\prave\Desktop\Tor Browser\Browser\firefox.exe', tbb_profile_path=r'C:\Users\prave\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
driver.get('check.torproject.org')
time.sleep(100000)

Note: if you get a error saying filenotfound blabla/browser create an empty folder named broser at that location

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Do I need the tbselerium for this to work? – Pedro Lopes Dec 20 '20 at 17:32
  • Yes , tor is a new system that is build on firefox you cannot directly use firefox profile – PDHide Dec 20 '20 at 17:43
  • This seemed to work :). Having a different issue now but not related to this post. – Pedro Lopes Dec 20 '20 at 18:29
  • You can use this to open chrome using tor.proxy but it works only for incognito mode – PDHide Dec 20 '20 at 18:33
  • can I ask you a question? Why do I need to make a folder named browser? Currently I needed to make 20 folders browser one inside each other because I loop through a list and every time I need a new one. Is there a way to disable this? – Pedro Lopes Dec 21 '20 at 21:04
  • Logs are generated inside that folder , I don't think you need 20 folders only one would be enough – PDHide Dec 22 '20 at 01:51
  • When I make a loop it says Browser/Browser doesn't exist. And when I loop again it says Browser/Browser/Browser doesn't exist – Pedro Lopes Dec 22 '20 at 20:50