com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 找不到 https://tax.ocgov.com/includes/jquery-2.2.3.min.js
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for https://tax.ocgov.com/includes/jquery-2.2.3.min.js
我正在尝试通过 HtmlUnit 在 https://tax.ocgov.com/tcweb/search_page.asp 上查找有效的包裹编号,因此我使用了以下 for 循环:
for (Integer pID=34056101; pID<34056111; pID++) {
HtmlPage page = webClient.getPage("https://tax.ocgov.com/tcweb/search_page.asp");
String i = pID.toString();
final HtmlForm form = page.getFormByName("searchparcel");
final HtmlTextInput taxIDInput = form.getInputByName("t_parcel_no");
final HtmlImageInput button = form.getInputByName("s_parcel");
taxIDInput.type(i);
final HtmlPage page2 = (HtmlPage) button.click();
//System.out.println(page2.getUrl().getPath());
if (page2.getUrl().getPath() == "/tcweb/search_parcel.asp")
{writer.println(pID);}
}
但是,我得到了这个错误:
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not
Found for https://tax.ocgov.com/includes/jquery-2.2.3.min.js
异常是由这行代码引起的:
final HtmlPage page2 = (HtmlPage) button.click();
我应该怎么做才能让我的程序正常工作?
您正在使用的页面有很多问题-只需打开浏览器控制台并自行查看....
开箱即用的 HtmlUnit 是为页面测试而编写的,因为与真实浏览器相比,此类错误的处理更加敏感。
但是你可以改变这个。
对我来说这段代码有效:
final String url = "https://tax.ocgov.com/tcweb/search_page.asp";
try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(1000);
final HtmlForm form = page.getFormByName("searchparcel");
final HtmlTextInput taxIDInput = form.getInputByName("t_parcel_no");
final HtmlImageInput button = form.getInputByName("s_parcel");
taxIDInput.type("34056101");
final HtmlPage page2 = (HtmlPage) button.click();
webClient.waitForBackgroundJavaScript(1000);
System.out.println("***********");
System.out.println(page2.asNormalizedText());
System.out.println("***********");
}
我正在尝试通过 HtmlUnit 在 https://tax.ocgov.com/tcweb/search_page.asp 上查找有效的包裹编号,因此我使用了以下 for 循环:
for (Integer pID=34056101; pID<34056111; pID++) {
HtmlPage page = webClient.getPage("https://tax.ocgov.com/tcweb/search_page.asp");
String i = pID.toString();
final HtmlForm form = page.getFormByName("searchparcel");
final HtmlTextInput taxIDInput = form.getInputByName("t_parcel_no");
final HtmlImageInput button = form.getInputByName("s_parcel");
taxIDInput.type(i);
final HtmlPage page2 = (HtmlPage) button.click();
//System.out.println(page2.getUrl().getPath());
if (page2.getUrl().getPath() == "/tcweb/search_parcel.asp")
{writer.println(pID);}
}
但是,我得到了这个错误:
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for https://tax.ocgov.com/includes/jquery-2.2.3.min.js
异常是由这行代码引起的:
final HtmlPage page2 = (HtmlPage) button.click();
我应该怎么做才能让我的程序正常工作?
您正在使用的页面有很多问题-只需打开浏览器控制台并自行查看....
开箱即用的 HtmlUnit 是为页面测试而编写的,因为与真实浏览器相比,此类错误的处理更加敏感。 但是你可以改变这个。
对我来说这段代码有效:
final String url = "https://tax.ocgov.com/tcweb/search_page.asp";
try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(1000);
final HtmlForm form = page.getFormByName("searchparcel");
final HtmlTextInput taxIDInput = form.getInputByName("t_parcel_no");
final HtmlImageInput button = form.getInputByName("s_parcel");
taxIDInput.type("34056101");
final HtmlPage page2 = (HtmlPage) button.click();
webClient.waitForBackgroundJavaScript(1000);
System.out.println("***********");
System.out.println(page2.asNormalizedText());
System.out.println("***********");
}