0

I am trying to open a tor browser window on ubuntu with python using selenium and then control it so that it goes to a link, puts in some key combinations, etc. when my code goes to open tor, it gives me a pop up saying "Unable to start tor, the torrc file is missing and could not be created" and then proceeds to hand on a tor window saying "waiting for Tor to start". I haven't even included the rest of the code yet for doing some actions on the web page because tor won't even open to begin with. the folder and file used by the tor browser as well as the torrc file (which does exist!) in /etc/tor all have full permissions for all users. This is the simple code that I am trying to run yet I'm getting the above error:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.firefox.options import Options
import os


binary = FirefoxBinary('/home/test/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/firefox')
driver = webdriver.Firefox(firefox_binary = binary)
driver.get("https://www.whatsmyip.org")

2 Answers2

0

Check if you are directing to the right driver file with firefox.exe extension

Try changing the location as well

I am using windows and here's an example:

driver=webdriver.Chrome("D:/OneDrive/Python/Sel_python/drivers/chromedriver.exe")
Libin Thomas
  • 829
  • 9
  • 18
  • Ok so I have tried to direct to the web driver I want to use which is geckodriver because for us built off of Firefox but when I direct to my geckodriver file , it just ends up opening regular Firefox and not tor – SamDaMan0520 Nov 25 '20 at 13:36
0

Got your point. I tried the below code in one of my project which worked fine.
Check if this works for you:

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

binary = 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")

Reference: Python Selenium binding with TOR browser

Libin Thomas
  • 829
  • 9
  • 18