0

我正在尝试从使用 MS Ajax 工具包的网站解析数据。代码运行时,抛出了大量异常。我还尝试使用 CHROME 作为带有 HtmlUnit 的浏览器版本,但它没有帮助。有任何想法吗?

我的代码:

public class MainPage {
final static String baseURI = "http://web1.seattle.gov/courts/cpi/DefendantList.aspx";
final static WebClient webClient = new WebClient(BrowserVersion.CHROME);    
static HtmlPage currentPage = null;

public static void main(String[] args) {                
    try {                       
        // java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);

        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        final HtmlPage mainPage = webClient.getPage(baseURI);
        final HtmlForm searchForm = mainPage.getFormByName("form1");

        searchForm.getInputByName("rtbDefLastName").setValueAttribute("Smith");
        searchForm.getInputByName("rtbDefFirstName").setValueAttribute("John");

        final HtmlPage resultPage = searchForm.getInputByName("btnSrchByDefName").click();              
        System.out.println(resultPage.asText());                            
    } catch (FailingHttpStatusCodeException | IOException e) {
        e.printStackTrace();
    }
}

}

和输出:

Nov 12, 2013 6:05:10 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Nov 12, 2013 6:05:10 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Nov 12, 2013 6:05:10 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'http://web1.seattle.gov/COURTS/SMCApp.css' [15:2] Error in style rule. (Invalid token "HTML". Was expecting one of: <S>, <LBRACE>, <COMMA>, <HASH>, ".", ":", "[", <S>.)
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'http://web1.seattle.gov/COURTS/SMCApp.css' [15:2] Ignoring the following declarations in this rule.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'http://web1.seattle.gov/courts/CPI/WebResource.axd?d=LMlbvM4qfEdzrlKVqIc-8mfNXM4PRJKfxIOMA8AV9PNLbn8G0v4aRHZWRGu2jfQxV_Ct0PNGkEjJ2YhGr40zd88yNUBWOMCpl84P3uR3Hu_GU0ul5VRWUXd5JszpaKtypLmwjMIyXOr3t6R-mMUsu2ukvVE1&t=633746128680000000' [5:1] Error in style rule. (Invalid token ".". Was expecting one of: <S>, <LBRACE>, <COMMA>.)
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'http://web1.seattle.gov/courts/CPI/WebResource.axd?d=LMlbvM4qfEdzrlKVqIc-8mfNXM4PRJKfxIOMA8AV9PNLbn8G0v4aRHZWRGu2jfQxV_Ct0PNGkEjJ2YhGr40zd88yNUBWOMCpl84P3uR3Hu_GU0ul5VRWUXd5JszpaKtypLmwjMIyXOr3t6R-mMUsu2ukvVE1&t=633746128680000000' [5:1] Ignoring the following declarations in this rule.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'http://web1.seattle.gov/courts/CPI/WebResource.axd?d=-NPRlHTVZOXOItWVoljD3-5QEqyuzmrc_N5sqREwsKSubbs3xFynzoyWV9KKr_ebcTtV3i1Gryofr1ihfTjh3Fl4DRZHIfs1BQqGP1nWnoWCJUG8_OpYA-eDNTEOAGIsHV2QkguThgv2DKkL0&t=633746128680000000' [5:1] Error in style rule. (Invalid token ".". Was expecting one of: <S>, <LBRACE>, <COMMA>.)
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'http://web1.seattle.gov/courts/CPI/WebResource.axd?d=-NPRlHTVZOXOItWVoljD3-5QEqyuzmrc_N5sqREwsKSubbs3xFynzoyWV9KKr_ebcTtV3i1Gryofr1ihfTjh3Fl4DRZHIfs1BQqGP1nWnoWCJUG8_OpYA-eDNTEOAGIsHV2QkguThgv2DKkL0&t=633746128680000000' [5:1] Ignoring the following declarations in this rule.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:11 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine handleJavaScriptException
INFO: Caught script exception
======= EXCEPTION START ========
EcmaError: lineNumber=[162] column=[0] lineSource=[null] name=[TypeError] sourceName=[http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100] message=[TypeError: Cannot read property "Validators" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100#162)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "Validators" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100#162)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:684)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:210)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:230)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:804)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:738)
    at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:869)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:874)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:845)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.executeOnChangeHandlerIfAppropriate(HtmlInput.java:491)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.setValueAttribute(HtmlInput.java:94)
    at MainPage.main(MainPage.java:27)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "Validators" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100#162)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    ... 17 more
Enclosed exception: 
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "Validators" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100#162)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
    at script.ValidatorOnChange(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100:162)
    at script.anonymous(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=NT3AT2bWfwLom1kHaizOG9d2hL1e26kfOo4ELbGnwf_XtVYj3DpkxtzewLCDFZ6ddnSK7Q9EQPbGQqmZgSgnaaxJQlwmqMXpv7C5gFvwzHiRihCfdK25rhDzWBjlKrs7YZhXhwP5c384PDlQ0&t=ffffffff9f6f7100#97(Function):1)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:210)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:230)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:804)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:738)
    at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:869)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:874)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:845)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.executeOnChangeHandlerIfAppropriate(HtmlInput.java:491)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.setValueAttribute(HtmlInput.java:94)
    at MainPage.main(MainPage.java:27)
== CALLING JAVASCRIPT ==

  function anonymous(event) {
      ValidatorOnChange(event);
  }

======= 例外结束 ========

Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController processSynchron
INFO: Re-synchronized call to http://web1.seattle.gov/courts/cpi/DefendantList.aspx
Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine handleJavaScriptException
INFO: Caught script exception
======= EXCEPTION START ========
EcmaError: lineNumber=[729] column=[0] lineSource=[null] name=[TypeError] sourceName=[http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43] message=[TypeError: Cannot read property "disabled" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43#729)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "disabled" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43#729)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:684)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:177)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:237)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:804)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:738)
    at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:869)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:874)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.doClickFireClickEvent(HtmlElement.java:1311)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1253)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1205)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1160)
    at MainPage.main(MainPage.java:30)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "disabled" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43#729)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    ... 18 more
Enclosed exception: 
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "disabled" from undefined (http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43#729)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3634)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1488)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1233)
    at script.Sys$WebForms$PageRequestManager$_onFormElementActive(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43:729)
    at script.Sys$WebForms$PageRequestManager$_onFormElementClick(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=wAKJQuapfi2h0tvgddshu6GwSBoo0uJ-Q4zq1fpZG1ZOiNZgZZNomCn_OChvdWzXkxwIbSpMmitsYmDHmDpi-_Muj2-QmYqFjgrU54gChUB4h0YeDFGq7JyV0GIClurbdmC9pRNWwqRbk5gkFzybU7XnF9F4YUtiRPHHsC0TgYUJHhHR0&t=ffffffffdca80a43:751)
    at script(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=GzSW1c3NKsncPwlvGy3qGT-vozDnuoTbJRITSlPr6OEXzpdb1saFCmLwjRyqYfH5pta6HhEtCCU0x1VKNwmwJGlYwl2L_LdE-PxNHQjfNmEnmdhuyKvS5W28hsds4a5GmaIHjebqkMQ1yQVwZheqwC9K9wwuMr2kLfxJsg2&t=ffffffffdca80a43:47)
    at script(http://web1.seattle.gov/courts/CPI/ScriptResource.axd?d=GzSW1c3NKsncPwlvGy3qGT-vozDnuoTbJRITSlPr6OEXzpdb1saFCmLwjRyqYfH5pta6HhEtCCU0x1VKNwmwJGlYwl2L_LdE-PxNHQjfNmEnmdhuyKvS5W28hsds4a5GmaIHjebqkMQ1yQVwZheqwC9K9wwuMr2kLfxJsg2&t=ffffffffdca80a43:2948)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:177)
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:237)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:804)
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:738)
    at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:869)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:874)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.doClickFireClickEvent(HtmlElement.java:1311)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1253)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1205)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1160)
    at MainPage.main(MainPage.java:30)
== CALLING JAVASCRIPT ==

  function (e) {
      return handler.call(element, new Sys.UI.DomEvent(e));
  }

======= 例外结束 ========

Nov 12, 2013 6:05:12 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.

似乎进行了 AJAX 调用,但是在生成网格时出现了一些异常,导致前端没有数据。

4

1 回答 1

1

我找到了让它工作的方法。这里有两点需要考虑:

  1. 本网站使用 Microsoft AJAX 工具包进行 AJAX 调用,HtmlUnit 库不太支持该工具包。我尝试了不同的浏览器版本,只有一个可以工作的是 CHROME。
  2. 进行 AJAX 调用后需要调用 waitForBackgroundJavaScript。我可以通过以下方式获取数据:

webClient.waitForBackgroundJavaScript(50000);

于 2013-11-18T19:35:23.317 回答