【问题标题】:Web Driver and Tor execution in javaJava中的Web驱动程序和Tor执行
【发布时间】:2015-06-08 09:51:24
【问题描述】:

我可以使用 Firefox 驱动程序连接到 tor,但我想知道我是否可以使用 phantomjs 或 html-unit 驱动程序连接到 tor?

对于 pantomjs,我尝试了以下代码

    String[] phantomArgs = new  String[] {
        "--webdriver-loglevel=NONE",
        "--webdriver=localhost:9150"
    };

    DesiredCapabilities dcaps = new DesiredCapabilities();
    dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());

    dcaps.setCapability( "phantomjs.cli.args", phantomArgs);
    WebDriver driver = new PhantomJSDriver(dcaps);

如果没有,我可以使用类似的免费代理服务器吗?

【问题讨论】:

  • 或者建议我在 selenium 中使用代理的其他方式,即使是付费的!

标签: selenium selenium-webdriver phantomjs tor


【解决方案1】:

很抱歉回答迟了。我没有亲自尝试使用 phantomjs,但我一直是所有主要浏览器的 Tor 的热心用户。我认为这里出现的问题是因为你没有设置代理类型 ie)你可以指示 SOCKS 代理配置

--proxy-type=socks5

因为 tor 是 socks 代理而不是 http 代理

ArrayList<String> phantom = new ArrayList<String>();
phantom.add("--proxy=localhost:9150");
phantom.add("--proxy-type=socks5");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantom);
driver = new PhantomJSDriver(capabilities);

希望这对您有所帮助...如果仍然无法正常工作,请返回。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多