gpt4 book ai didi

java - htmlunit 无法从未定义中读取属性 "push"

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:13:11 24 4
gpt4 key购买 nike

我正在尝试使用 htmlunit 抓取网站。每当我运行它时,它只会输出以下错误:

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.getOptions().setThrowExceptionOnScriptError(false);

在您尝试获取页面之前。这会强制 htmlunit 忽略错误。但是,如果抛出错误的 javascript 对于获取您正在废弃的数据很重要(希望它不是),那么这可能不会在 100% 的时间内起作用。如果这不起作用,请尝试将 Selenium 与 ChromeDriver 或 GhostDriver 结合使用。

Source

关于java - htmlunit 无法从未定义中读取属性 "push",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40657249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com