0

我正在尝试通过 HTMLUnit 访问我的 FritzBox,但出现错误,我的浏览器太旧且不受支持。

    try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
final HtmlPage page1 = webClient.getPage("http://fritz.box/");
System.out.println(page1.getWebResponse().getContentAsString());
}
4

1 回答 1

0

从第一个分析开始:UI 会进行一些浏览器检查,以确保您的浏览器支持使用的功能。

检查看起来像这样(参见 js/browser.js)

var ok = true,
    gNbc;
try {
    if (!gNbc) {
        ok = ok && window.Proxy && typeof new window.Proxy({}, function() {}) === "object";
        ["1"].forEach(function() {});
        ok = ok && window.Promise && typeof new window.Promise(function() {}) === "object";
        ok = ok && window.Blob && typeof new window.Blob(["<a></a>"], {
            type: "text/html"
        }) === "object";
        ok = ok && window.requestAnimationFrame && true;
        ok = ok && window.Promise.resolve(true).finally(function() {});
    }
} catch (err) {
    ok = false;
}
if (!ok) {
    window.location.href = "sorry.lua";
}

HtmlUnit(从 2.56 版开始)不支持 javascript 代理,这就是此检查失败的原因,最后您被重定向到 /sorry.lua。

再次 - 请在https://github.com/HtmlUnit/htmlunit打开一个问题。

于 2021-12-23T16:49:04.450 回答