【问题标题】:How to use the tor browser as web driver selenium?如何使用 tor 浏览器作为 web 驱动程序 selenium?
【发布时间】:2019-02-22 23:42:13
【问题描述】:

我遇到了这个异常:

线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关详细信息,请参阅https://github.com/mozilla/geckodriver。最新版本可以从https://github.com/mozilla/geckodriver/releases下载

这是我的代码:

String torPath = "C:\\Users\\camil\\Desktop\\Tor Browser\\Browser\\firefox.exe";
String profilePath = "C:/Users/camil/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);

torProfile.setPreference("webdriver.load.strategy", "unstable");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(binary);
firefoxOptions.setProfile(torProfile);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

【问题讨论】:

  • 其他用户将您的问题标记为低质量和需要改进。我重新措辞/格式化您的输入,使其更容易阅读/理解。请查看我的更改以确保它们反映您的意图。如果您对我有其他问题或反馈,请随时给我留言。
  • 除此之外:你试过东那个吗?将路径设置为系统属性

标签: java selenium-webdriver


【解决方案1】:

使用现有浏览器配置文件成功启动 Tor:

package navi;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class Tor_browser_test {
    private static WebDriver driver;

    @BeforeClass
    public static void setUpClass() {
        FirefoxOptions options = new FirefoxOptions();
        ProfilesIni allProfiles = new ProfilesIni();         
        FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
        options.setProfile(selenium_profile);
        options.setBinary("C:\\Users\\pburgr\\Desktop\\Tor browser\\Browser\\firefox.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();}
    @Before
    public void setUp() {}
    @After
    public void tearDown() {}
    @AfterClass
    public static void tearDownClass() {driver.quit();}
    @Test
    public void tor_browser_test() throws InterruptedException {
        driver.get("https://www.google.com");
        Thread.sleep(5000);
    }
}

【讨论】:

  • 现在我在 ProfilesIni 类构造函数中遇到了另一个问题,配置文件是在 null 中创建的,如果没有这部分 tor 代码,它会告诉我代理有问题
  • 不幸的是我也没有通过代理。为什么要使用 Tor?
  • 我想创建一个自动创建 Instagram 帐户的程序。这就是为什么我想利用 tor 的匿名性
  • 这种方式不合适,使用沙箱不需要匿名,见instagram.com/developer/sandbox
  • 感谢您提供这些信息,但我也想扩展到其他社交网络,我认为这是匿名进行此操作的最佳方式,感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-21
相关资源
最近更新 更多