从Selenium调用Tor的WebDriver



我需要Tor的Webdriver实例,以便能够在Windows中从selenium、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 Browser页面。它没有按要求加载google.com。我知道配置文件是有效的/兼容的,因为我可以成功地启动浏览器和配置文件:

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

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

能做到吗?如果是,如何?我正在寻找Java代码。

    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:torTor BrowserBrowser
    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);

使用此代码

相关内容

最新更新