我试图抓取使用htmlunit的网站。每当我运行它,虽然它只是输出下列错误:htmlunit无法从undefined读取属性“推”
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "push" from undefined (https://www.kinoheld.de/dist/prod/0.4.7/widget.js#1)
现在我不知道很多关于JS,但我读了push
是某种数组的操作。这对我来说似乎是标准的,我不知道为什么它不会被htmlunit支持。
这里是代码我使用至今:
public static void main(String[] args) throws IOException {
WebClient web = new WebClient(BrowserVersion.FIREFOX_45);
web.getOptions().setUseInsecureSSL(true);
String url = "https://www.kinoheld.de/kino-muenchen/royal-filmpalast/vorstellung/280823/?mode=widget&showID=280828#panel-seats";
web.getOptions().setThrowExceptionOnFailingStatusCode(false);
web.waitForBackgroundJavaScript(9000);
HtmlPage response = web.getPage(url);
System.out.println(response.getTitleText());
}
我缺少什么?有没有办法解决这个问题呢? 在此先感谢!
如果不支持,我想你应该向开发人员申请一个新功能。 –
何时发生错误?在'web.getPage(url)'或者'response.getTitleText()'调用之后? – Jack
@Jack'web.getPage(url)'后出现错误,因为我可以注释掉'response.getTitleText()'并且它仍然会被抛出,即使当'web.getOptions()。setThrowExceptionOnScriptError(false );'(见下面的答案)被插入。 – Maverick283