Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何避免/修复HTMLUnit中的ScriptException错误?_Javascript_Java_Htmlunit - Fatal编程技术网

Javascript 如何避免/修复HTMLUnit中的ScriptException错误?

Javascript 如何避免/修复HTMLUnit中的ScriptException错误?,javascript,java,htmlunit,Javascript,Java,Htmlunit,我正在尝试访问路由器上的一个网站,这样我就可以自动控制一个鱼缸。当我尝试使用HTML单元连接到网站时,会出现一个错误: Nov 24, 2019 7:46:15 PM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException SEVERE: Error during JavaScript execution ======= EXCEPTION START ======== Ecm

我正在尝试访问路由器上的一个网站,这样我就可以自动控制一个鱼缸。当我尝试使用HTML单元连接到网站时,会出现一个错误:

Nov 24, 2019 7:46:15 PM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException
SEVERE: Error during JavaScript execution
======= EXCEPTION START ========
EcmaError: lineNumber=[108] column=[0] lineSource=[null] name=[ReferenceError] sourceName=[script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10)] message=[ReferenceError: "nsys_translator" is not defined. (script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10)#108)]
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "nsys_translator" is not defined. (script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10)#108)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:883)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:812)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:784)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2542)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2535)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:171)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.lambda$executeEventHandlersIfNeeded$0(HtmlPage.java:1248)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1248)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:249)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:541)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450)
    at AlkOutput.main(AlkOutput.java:43)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "nsys_translator" is not defined. (script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10)#108)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4334)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4312)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:4406)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:2009)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1948)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1752)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1010)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:424)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:322)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3628)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:805)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:868)
    ... 22 more
Enclosed exception: 
net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "nsys_translator" is not defined. (script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10)#108)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4334)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4312)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:4406)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:2009)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1948)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1752)
    at script(script in http://24.92.140.58:80/outsetup.sht from (76, 32) to (120, 10):108)
    at script(script in http://24.92.140.58:80/outsetup.sht from (-1, -1) to (-1, -1))
    at script(script in http://24.92.140.58:80/outsetup.sht from (-1, -1) to (-1, -1))
    at script(script in http://24.92.140.58:80/outsetup.sht from (-1, -1) to (-1, -1))
    at script(script in http://24.92.140.58:80/outsetup.sht from (-1, -1) to (-1, -1))
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1010)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:424)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:322)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3628)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:805)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:868)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:812)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:784)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2542)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2535)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeAtTargetListeners(EventListenersContainer.java:379)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:171)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.lambda$executeEventHandlersIfNeeded$0(HtmlPage.java:1248)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1248)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:249)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:541)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450)
    at AlkOutput.main(AlkOutput.java:43)
== CALLING JAVASCRIPT ==
  function () {
      document.removeEventListener("DOMContentLoaded", arguments.callee, false);
      T.ready();
  }
======= EXCEPTION END ========
我不知道如何绕过这个错误,以便我可以访问该网站。我尝试使用命令
WebClient.getOptions().setThroweExceptionOnScriptError(false)
忽略错误,但这似乎无法解决问题。我还试着切换
BrowserVersion
,但也没用。也许问题出在网站上。我无法更改网站上的代码。这是我的密码

public class AlkOutput {

    public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {

        DefaultCredentialsProvider cred = new DefaultCredentialsProvider();
        cred.addCredentials(username, password); //I didn't include real username / password for privacy

        WebClient web = new WebClient(BrowserVersion.INTERNET_EXPLORER);

        web.getOptions().setThrowExceptionOnScriptError(false);

        web.setCredentialsProvider(cred);

        HtmlPage page = web.getPage("http://24.92.140.58:80/outsetup.sht"); //error is on this line

        web.close();
   }
}

你能不能检查一下在真正的浏览器上是否发生了同样的错误

设置WebClient.getOptions().SetThroweExceptionOnScriptError(false);仍然会报告错误,但会继续处理页面中的js(与浏览器一样)


为什么您认为它不起作用-您得到了预期的页面吗?

欢迎使用堆栈溢出!如果你对你的代码有疑问,记得提供一个例子,当我在chrome中查看网站时,错误似乎仍然会发生。我已经读到,真正的浏览器可以忽略这些错误,仍然可以工作,但HTML单元很难忽略这些错误。当我在真正的浏览器上加载页面时,页面工作正常。我的目标是将命令输入到网站上的一个文本框中,并与真正的浏览器配合使用。我想在无头浏览器上实现这一点,以最小化负载。