无法在Java中使用HtmlUnit从URL获取id为的元素
无法使用Java
中的HTMLUnit
从https://www.mohavecounty.us/ContentPage.aspx?id=111&cid=869&parcel=10272001
获取具有id="parcelMailingAddressResult"
的元素
如果你转到上面的URL,你会看到有一个邮寄地址。对该网站的DOM检查表明,该地址具有上述ID。我已经尝试了几天,使用Java/HTMLUnit获取该邮件地址,但没有一次尝试成功
下面是我在同一代码中尝试的三种方法
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
final WebClient webClient = new WebClient();
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws IOException {
System.out.println("handleRefresh");
}
});
HtmlPage page = (HtmlPage) webClient.getPage("https://www.mohavecounty.us/ContentPage.aspx?id=111&cid=869&parcel=10272001");
DomElement ownerAddresses = page.getElementById("parcelMailingAddressResult");
NodeList nodes = page.getElementsByTagName("parcelMailingAddressResult");
final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@class='container-fluid row']").get(0);
我希望变量ownderAddresses
和节点包含包含所有者地址的信息。我希望div
包含一些其他信息,并且在我将get(0)
更改为get(<someHigherInteger>)
后,还包含有关所有者地址的信息
取而代之:
ownerAddresses = null
(在执行ownerAddress=…)李>- 节点的大小为0(在执行节点=…)李>
final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@class='container-fluid row']").get(0);
大约13秒后,抛出以下异常:
例外情况:
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
这意味着(HtmlDivision) page.getByXPath("//div[@class='container-fluid row']")
的长度为0
共 (0) 个答案