它可以在我尝试过的其他站点上完美运行,但是在“ https://www.reddit.com”或它的任何子站点上使用它都会给我一个例外。
似乎来自https://www.redditstatic.com,reddit使用的所有图像和静态文件都是从该域加载的,因此您的浏览器不会发送cookie,这反过来使reddit加载速度更快。
给我例外的最简化的代码版本是:
try (final WebClient webClient = new WebClient() ){
final HtmlPage page = webClient.getPage("https://www.reddit.com");
}
还使用BrowserVersion.FIREFOX_52不能修复它。
输出是这样的:
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: missing formal parameter (https://www.redditstatic.com/desktop2x/Governance~Profile~ProfileHomepage~ProfilePostComments~R2CommentsPage~R2Listing~Reddit.1b53456530932e442624.js#1)
...
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: missing formal parameter (https://www.redditstatic.com/desktop2x/Governance~Profile~ProfileHomepage~ProfilePostComments~R2CommentsPage~R2Listing~Reddit.1b53456530932e442624.js#1)
...
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: missing formal parameter (https://www.redditstatic.com/desktop2x/Governance~Profile~ProfileHomepage~ProfilePostComments~R2CommentsPage~R2Listing~Reddit.1b53456530932e442624.js#1)