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/