我试图遍历一个网站,但在他们的一个页面上,我得到了这样的错误:
EcmaError: lineNumber=[671] column=[0] lineSource=[null] name=[TypeError] sourceName=[https://reservations.besodelsolresort.com/asp/CalendarPopup.js] message=[TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)有没有什么我可以忽略这个错误的方法?我并不特别关心日历是否正确加载。
发布于 2014-08-31 19:31:39
Alexey的答案是给HttpUnit的。对于HtmlUnit,代码是类似的
WebClient client = new WebClient();
client.getOptions().setThrowExceptionOnScriptError(false);发布于 2015-12-10 18:41:03
我尝试使用Matthews answer,并需要使用以下方式覆盖newWebClient()方法:
HtmlUnitDriver driver = new HtmlUnitDriver(true) {
@Override
protected WebClient newWebClient(BrowserVersion version) {
WebClient webClient = super.newWebClient(version);
webClient.getOptions().setThrowExceptionOnScriptError(false);
return webClient;
}
};https://stackoverflow.com/questions/21294707
复制相似问题