简体   繁体   中英

Failed to launch Tor Browser

I tried this many times:

from tbselenium.tbdriver import TorBrowserDriver
 with TorBrowserDriver("/path/to/TorBrowserBundle/") as driver:
    driver.get('https://check.torproject.org')

*from here; https://github.com/webfp/tor-browser-selenium

With mine as

from tbselenium.tbdriver import TorBrowserDriver
 with TorBrowserDriver("C:\Program Files (x86)\TOR\Tor Browser\Browser\firefox.exe") as driver:
    driver.get('https://check.torproject.org')

But, failed to load TOR:

tbselenium.exceptions.TBDriverPathError: TBB path is not a directory C:\Program Files (x86)\TOR\Tor Browser\Browser[image]irefox.exe

That failed '[image]' is this: https://imgur.com/LqwV3qv

Why it become like that?

Backslashes have special meaning on a str . In order to literally use them as characters, you need to escape them:

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver('C:\\Program Files (x86)\\TOR\\Tor Browser\\Browser\\firefox.exe') as driver:
    driver.get('https://check.torproject.org')

Since you are using library that does not support Windows or macOS https://github.com/webfp/tor-browser-selenium#compatibility it will not be possible to use that particular library until author or any other contributor fix it for other platforms except Debian and Ubuntu.

Some users already asked that in Issues of that repository https://github.com/webfp/tor-browser-selenium/issues/81 and here are some clues in which direction to investigate to make it work for macOS https://github.com/webfp/tor-browser-selenium/issues/106

One of possible workaround in case if you need privacy is to start Tor (it will use it default port 9150) and use PySocks for routing traffic, Python3 example

import socks
import socket
from urllib.request import urlopen

socks.set_default_proxy(socks.SOCKS5, "localhost", 9150)
socket.socket = socks.socksocket
print(urlopen('http://icanhazip.com').read())

Or the same idea using webdriver

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--proxy-server=socks5://127.0.0.1:9150")
driver = webdriver.Chrome(executable_path='chromedriver', options=chrome_option$

driver.get('https://whatismyipaddress.com/')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM