【问题标题】:Invoking WebDriver for Tor from Selenium从 Selenium 为 Tor 调用 WebDriver
【发布时间】:2015-02-06 10:51:39
【问题描述】:

我需要一个 Tor 的 Webdriver 实例,以便能够从 selenium、Windows 中的 java 代码在 Tor 中启动 google.com,并能够搜索目标字符串

我的代码在下面

String torPath = "..Installations\\Tor\\Tor Browser\\Browser\\firefox.exe";
String profilePath = "..Installations\\Tor\\TorBrowser\\Browser\\TorBrowser\\Data\\Browser\\profile.default";
FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
FirefoxBinary binary = new FirefoxBinary(new File(torPath));
FirefoxDriver driver = new FirefoxDriver(binary, profile);
driver.get("http://www.google.com");

这会导致打开一个空白的 Tor 浏览器页面。它不会根据需要加载 google.com。我知道配置文件有效/兼容,因为我可以成功启动浏览器和配置文件:

binary.startProfile(profile, profilePath, ""));

我看过类似的问题,但没有得到满意的答案。

可以吗?如果是,如何? 我正在寻找 Java 代码。

【问题讨论】:

    标签: java firefox selenium selenium-webdriver tor


    【解决方案1】:
        FirefoxDriver firefoxDriver;
        File torProfileDir = new File("C:\\tor\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default");
        FirefoxBinary binary = new FirefoxBinary(new File( "C:\\tor\\Tor Browser\\Browser\\firefox.exe"));//C:\tor\Tor Browser\Browser
        FirefoxProfile torProfile = new FirefoxProfile(torProfileDir);
        torProfile.setPreference("webdriver.load.strategy", "unstable");
        binary.startProfile(torProfile, torProfileDir);
    
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.socks", "127.0.0.1");
        profile.setPreference("network.proxy.socks_port", 9150);
    

    使用此代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多