java - 如何使用 tor 浏览器使用 selenium webdriver (java)?到目前为止,我已经尝试过以下代码,但收到消息 : 'tor failed to start'

标签 java selenium selenium-webdriver automation tor

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

public class torr1 {

    public static void main(String[] args) {
        System.setProperty("webdriver.firefox.marionette",
                "C:\\Users\\ghorh\\Documents\\selenium-bazinga\\Drivers\\geckodriver.exe");
        String torPath = "C:\\Users\\ghorh\\Desktop\\Tor Browser\\Browser\\firefox.exe";
        String profilePath = "C:\\Users\\ghorh\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default";

        File torProfileDir = new File(profilePath);
        FirefoxBinary binary = new FirefoxBinary(new File(torPath));
        FirefoxProfile torProfile = new FirefoxProfile(torProfileDir);

        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(binary);
        options.setProfile(torProfile);
        options.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
        WebDriver driver = new FirefoxDriver(options);
        driver.get("http://google.co.in");

    }

}

到目前为止,我已经尝试了上面的代码,但收到消息:“tor 无法启动”。有人可以帮助了解上述代码需要进行哪些更改。

最佳答案

您正在尝试使用 FireFox 驱动程序。 尝试使用自述文件中指定的 TorBrowserDriver:https://github.com/webfp/tor-browser-selenium

或者如果您想使用 firefox - 使用可以从下一个链接下载的 GeckoDriver: https://github.com/mozilla/geckodriver/releases/tag/v0.26.0

关于java - 如何使用 tor 浏览器使用 selenium webdriver (java)?到目前为止,我已经尝试过以下代码,但收到消息 : 'tor failed to start' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58888954/

相关文章:

ruby - 不支持的命令行标志 : --ignore-certificate-errors (in Ruby)

java - Selenium 网络驱动程序 : How many times does a driver try to find element with an implicit wait timeout?

java - 在 Selenium 中是否有使用 window().setSize 的替代方法?

java - EJB 3 : Can't inject bean in client code, 两者都由同一个容器管理

java - Java 中的 Setter 参数最终

java - log4j不会在系统中创建日志文件

python - 如何使用 Selenium-Python 从多选列表中选择多个选项?

java - Eclipse IDE 显示 JPA 中复合主键类的错误

android - 单击 span 和 div 中包含的文本

selenium - XPATH和元素的文本不断更新,什么是识别元素的最佳方法