我正在尝试使用 HTMLUnit 获取此页面,但似乎 HTMLUnit 进入无限循环并崩溃。
我一直试图找到原因,但我放弃了。我试过了:
- 从 SVN HTMLUnit 获取最新代码
- 使用不同的浏览器
- 尝试调试,但我找不到原因。
如果我使用 webClient.setJavaScriptEnabled(false);
我可以获取该站点,但未执行重要的脚本。所以,问题在于 JavaScript。
这是一个运行到循环的示例代码:
String url = "http://www.tjpe.jus.br/processos/consulta1grau/oleConsultaProcesso.asp?
nume=00123335620128170990&modalidade=6";
final List collectedAlerts = new ArrayList();
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
webClient.setThrowExceptionOnScriptError(false);
webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
webClient.waitForBackgroundJavaScript(10000);
webClient.waitForBackgroundJavaScriptStartingBefore(10000);
try {
final HtmlPage page1 = webClient
.getPage(url);
page1.asXml();
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是错误:
Jan 4, 2013 11:39:05 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Jan 4, 2013 11:39:05 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Jan 4, 2013 11:39:43 PM com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine
handleJavaScriptException
INFO: Caught script exception
======= EXCEPTION START ========
Exception class=[java.lang.RuntimeException]
com.gargoylesoftware.htmlunit.ScriptException: Exception invoking go
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run
(JavaScriptEngine.java:665)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:587)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call
(ContextFactory.java:534)
...
Caused by: java.lang.StackOverflowError
at java.lang.reflect.Method.copy(Unknown Source)
at java.lang.reflect.ReflectAccess.copyMethod(Unknown Source)
....
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:432)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
======= EXCEPTION END ========
我使用的 URL 是公开的,所以可以自由访问。
请,如果有人可以帮助我,我将不胜感激。