gpt4 book ai didi

java - com.gargoylesoftware.htmlunit.ElementNotFoundException : elementName=[form] attributeName=[name] attributeValue=[docSearch]

转载 作者:行者123 更新时间:2023-12-01 18:31:55 29 4
gpt4 key购买 nike

我正在尝试访问 https://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jspdocSearch 形式使用最新 HTMLUnit 版本 (2.37.0) 的网页。正如您使用 Firefox 的 DOM Inspector 所看到的,有这样一个表单

WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
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://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jsp");
webClient.waitForBackgroundJavaScript(1000000);
webClient.waitForBackgroundJavaScriptStartingBefore(100000);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
page.getEnclosingWindow().getJobManager().waitForJobs(1000000);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.waitForBackgroundJavaScriptStartingBefore(1000000);
HtmlForm form = page.getFormByName("docSearch");

上面代码的最后一行给出了以下异常:

com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[form] attributeName=[name] attributeValue=[docSearch]

关于我可以在代码中尝试什么来访问 docSearch 表单,有什么建议吗?您认为这是 HTMLUnit 本身的问题吗?我应该将此问题作为问题提交到 HTMLUnit 的 GitHub 网站上吗?

最佳答案

为此花费了一些时间来构建完整的示例。该页面只能在美国使用 - 我必须设置一个 VPN 才能访问该页面。示例包含一些提示;希望有帮助。

final String url = "https://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jsp";

try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
// webClient.getOptions().setUseInsecureSSL(true);

// open the url, this will do a redirect to the login page
HtmlPage page = webClient.getPage(url);
// System.out.println(page.asXml());
// System.out.println("--------------------------------");

// click the Public User Login
for (DomElement elem : page.getElementById("middle_left").getElementsByTagName("input")) {
if (elem instanceof HtmlSubmitInput
&& "Login".equals(((HtmlSubmitInput) elem).getValueAttribute())) {
page = elem.click();
break;
}
}
// System.out.println(page.asXml());
// System.out.println("--------------------------------");

// search by owner name
HtmlInput ownerInput = (HtmlInput) page.getElementById("TaxAOwnerIDSearchString");
ownerInput.type("Trump");
// click submit
for (DomElement elem : page.getElementsByTagName("input")) {
if (elem instanceof HtmlSubmitInput) {
page = elem.click();
}
}
// System.out.println(page.asXml());
// System.out.println("--------------------------------");

System.out.println(page.asText());

关于java - com.gargoylesoftware.htmlunit.ElementNotFoundException : elementName=[form] attributeName=[name] attributeValue=[docSearch],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60148335/

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