【问题标题】:How to run the Tor Browser with Selenium?如何使用 Selenium 运行 Tor 浏览器?
【发布时间】:2017-10-31 10:41:02
【问题描述】:

我正在尝试通过 Selenium 自动测试 Tor 浏览器,但到目前为止我还不能让它工作。我所有的尝试都是以下代码的某种变体:

FirefoxProfile profile = new FirefoxProfile(new File("/Users/MyUsername/Library/Application Support/TorBrowser-Data/Browser/x1v4coki.default"));
profile.setPreference("webdriver.load.strategy", "unstable");
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.socks", "127.0.0.1");
profile.setPreference("network.proxy.socks_port", 9150);
FirefoxBinary binary = new FirefoxBinary(new File("/Applications/TorBrowser.app/Contents/MacOS/firefox"));
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
options.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver(options);

当最后一行被执行时,Tor 浏览器成功启动。但是,程序会挂起一分钟左右,最终会抛出以下异常:

Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: '...', ip: '...', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver

当我省略 profile.setPreference(...) 行时,会引发相同的异常。 我正在使用 Tor 浏览器 7.0.8、geckodriver 0.19.0 和 Selenium 3.6。

有人可以帮我找出导致异常的原因吗?

【问题讨论】:

  • 不要将 geckodriver 与 tor 一起使用,因为 geckodriver 是为较新的 FF 版本而制作的,而 Tor 是较旧的 FF 前叉。参考stackoverflow.com/questions/39134419/…
  • 感谢您的建议,但我需要 geckodriver 来通过 Selenium 操作 Tor 浏览器。我已经遇到了您提到的链接,并尝试了相同的解决方案。但是,我使用 geckodriver 0.18.0 而不是 0.19.0 让它工作。
  • 你用最新的 Geckodriver 0.20 试过了吗?

标签: selenium tor tor-browser-bundle


【解决方案1】:

使用 geckodriver 0.18.0 而不是 0.19.0 解决了我的问题。

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 2018-10-31
    • 2019-09-05
    • 1970-01-01
    • 2019-07-01
    • 2013-06-11
    • 2016-03-22
    • 1970-01-01
    • 2019-02-22
    相关资源
    最近更新 更多