关于java:HTMLUnit解析aspx

HTMLUnit parsing aspx

我正在尝试使用HTMLUnit解析以下页面http://www.vermittlerregister.org。 但是关于它的问题是,我没有得到所请求的页面。 相反,我得到那个网站的超时页面,这对我来说没有任何意义。

1
2
final WebClient webClient = new WebClient();
webClient.getPage("http://www.vermittlerregister.org");

我通过控制台收到的唯一警告是:

com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNUNG: Obsolete content type encountered:
'application/x-javascript'.

这不应该引起按要求获取其他页面的问题。

顺便说一句:如果我使用的是标准的JAVA Api java.net.URL,则可以获取正确的页面内容。


您正在获取的页面上有刷新说明-半小时后,用户将重定向到超时消息:

1
2
<meta id="ctl00_MetaRefresh" http-equiv="REFRESH"
content="1800;url=http://www.vermittlerregister.org:80//system/logout.aspx?timeout=true" />

HtmlUnit需要确定是要给您当前页面还是刷新要发送给您的页面。 它的默认行为是立即遵循所有刷新指令(WebClient使用ImmediateRefreshHandler)。 您可以将其更改为NiceRefreshHandler,从而可以根据其延迟时间选择要遵循的刷新:

1
2
3
final WebClient webClient = new WebClient();
webClient.setRefreshHandler(new NiceRefreshHandler(5));
webClient.getPage("http://www.vermittlerregister.org");

如果延迟不超过5秒,这将告诉WebClient刷新,并且将忽略页面上30分钟的刷新指令。