我正在尝试通过HTMLUnit访问我的HTMLUnit,但发现我的浏览器太老,不受支持的错误。
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());
}发布于 2021-12-23 16:49:04
从第一个分析: 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上打开一个问题。
https://stackoverflow.com/questions/70448591
复制相似问题