3

How can I install the tor browser to make it useable in Python using Selenium?

I have tried sudo apt-get install tor-browser, but I don't know where it gets installed, hence what to put in the PATH variable (or in executable-path).

My goal is to

  1. install Tor browser

  2. open Tor Browser with Python Selenium

  3. go to a website.

3 Answers 3

4

I was able to run the Tor Browser on MacOS using Selenium. First, install the Tor Browser by downloading the appropriate package from here. MacOS will prompt you to move the contents to the Applications folder. Run TorBrowser to see if it works. Leave the TorBrowser running and run the following code.

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

binary = FirefoxBinary("/Applications/TorBrowser.app/Contents/MacOS/firefox")
driver = webdriver.Firefox(firefox_binary= binary)
driver.get("https://check.torproject.org/")

On Ubuntu, you can just leave the unzipped folder where it is. Test that TorBrowser works by double-clicking the TorBrowser icon in the folder. After spending a lot of time trying to make Tor work with Selenium on Ubuntu, I gave up and concluded that it might be easier to use a different tool specialized for Tor. I tried tor-browser-selenium link, which worked like a charm. This the code from that repository that worked for me:

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("/path/to/tbb/tor-browser_en-US/") as driver:
    driver.get('https://check.torproject.org') 

Prior to running this above code, you may have to export the environment variable TBB_PATH as follows, otherwise you will get an error stating that TBB_PATH is undefined:

export TBB_PATH=/path/to/tbb/tor-browser_en-US/

I didn't try Windows.

Sign up to request clarification or add additional context in comments.

Comments

0

To see your TorBrowser path and binary open Tor and under the three stripe menu on the top right go Help>Troubleshooting Information

Comments

-1

It's

sudo apt-get install torbrowser-launcher

and torbrowser-launcher gets located in /bin.

But you can just download the newest version from the official website, unpack and run.

3 Comments

Unable to locate package torbrowser-launcher
Works in ubuntu 16.04. Anyway, why not download the package from official website of torbrowser?
Updated the server to the latest version, now installation works. When I try to run it with Python however, I get the error selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/torbrowser-launcher unexpectedly exited. Status code was: 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.