python - 无法启动Tor浏览器

标签 python selenium tor

我尝试了很多次:

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


*从这里; https://github.com/webfp/tor-browser-selenium

以我为

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')


但是,无法加载TOR:

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


失败的“ [image]”是这样的:
https://imgur.com/LqwV3qv

为什么会变成这样?

最佳答案

Backslashes have special meaning on a str。为了从字面上使用它们作为字符,您需要对它们进行转义:

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')

关于python - 无法启动Tor浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49987197/

相关文章:

java - 如何在 Tor 中使用 HtmlUnit?

python - 使用 pandas 创建新列时的条件分割

javascript - 使用selenium通过window.open下载文件

c# - 使用 Selenium 2 的 IWebDriver 与页面上的元素进行交互

javascript - Web 驱动程序示例不起作用

C# Selenium - 无法启动 Tor

python - 使用 Gunicorn 和 Gevent 运行 Flask 时使用请求发出非阻塞请求

python - 将 jupyter lab notebook 转换为脚本而不添加注释和单元格之间的新行

python - 使用 discord.py 时 ffmpeg 失败

networking - 使用 tor 作为 SOCKS5 代理与 python urllib2 或 mechanize