【问题标题】:Java Selenium open TOR browserJava Selenium 打开 TOR 浏览器
【发布时间】:2019-12-23 21:18:35
【问题描述】:

我尝试通过 Java + Selenium + CheckoDriver + Tor 浏览器打开 Tor 浏览器。下面的代码打开 Tor 浏览器,但出现“Tor 无法启动”错误。也许有人遇到这个问题或有其他解决方案来解决问题(仅在 Java 上)谢谢!

 public static void test3() {
                System.setProperty("webdriver.gecko.driver", "C:\\tor\\geckodriver.exe");
                System.setProperty("webdriver.firefox.marionette", "C:\\tor\\geckodriver.exe");

                FirefoxOptions options = new FirefoxOptions();
                FirefoxProfile torProfile = new FirefoxProfile(new File("C:\\tor\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"));
                torProfile.setPreference("network.proxy.type", 1);
                torProfile.setPreference("network.proxy.socks", "127.0.0.1");
                torProfile.setPreference("network.proxy.socks_port", 9150);
                options.setBinary("C:\\tor\\Tor Browser\\Browser\\firefox.exe");
                options.setProfile(torProfile);
                options.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);

                FirefoxDriver driver = new FirefoxDriver(options);
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                driver.navigate().to("http://www.google.com");
            }

我想,也许是 setPreference ( proxy.. ) 的问题

【问题讨论】:

    标签: java selenium proxy tor firefox-profile


    【解决方案1】:

    要使用Selenium、GheckoDriver和Java打开TOR浏览器,需要先通过Runtime.getRuntime().exec()启动守护进程,可以使用以下解决方案:

    package demo;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.firefox.FirefoxProfile;
    
    public class A_Tor_Firefox {
    
        public static void main(String[] args) throws IOException {
    
    
        Runtime.getRuntime().exec("C:/Users/Debanjan.B/Desktop/Tor Browser/Browser/TorBrowser/Tor/tor.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Users\\Debanjan.B\\Desktop\\Tor Browser\\Browser\\firefox.exe");
        FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Debanjan.B\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"));
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.socks", "127.0.0.1");
        profile.setPreference("network.proxy.socks_port", 9150);
        profile.setPreference("network.proxy.socks_remote_dns", "False");
        options.setProfile(profile);
        WebDriver driver = new FirefoxDriver(options);
        driver.get("http://check.torproject.org");
    
        }
    }
    

    【讨论】:

    • 使用了你的例子,但是打开了 Firefox 浏览器
    • @тарас дідик 查看更新的答案并让我知道状态
    • 得到了同样的结果。显示“Tor 启动失败”错误
    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 2020-04-07
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 2022-06-11
    • 2017-01-01
    • 1970-01-01
    相关资源
    最近更新 更多