类型错误:在对象函数 Object() 中找不到函数条目

问题描述

我正在使用 htmlunit 来获取这个网页

https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies

Maven 依赖:

<dependency>
      <groupId>net.sourceforge.htmlunit</groupId>
      <artifactId>htmlunit</artifactId>
      <version>2.49.1</version>
</dependency>

我收到以下错误

Exception in thread "main" ======= EXCEPTION START ========
EcmaError: lineNumber=[2] column=[0] linesource=[<no source>] name=[TypeError] sourceName=[https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js] message=[TypeError: Cannot find function entries in object function Object() {
    [native code]
}. (https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js#2)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function entries in object function Object() {
    [native code]
}. (https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js#2)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:949)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:650)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:540)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:353)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:829)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:805)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:110)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1022)
        at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:196)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeDeferredScriptsIfNeeded(HtmlPage.java:1474)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:259)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:677)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:559)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:474)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:521)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:502)
        at rpvs.WebScraping.main(WebScraping.java:88)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function entries in object function Object() {
    [native code]
}. (https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js#2)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4396)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4374)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4407)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeErrorById(ScriptRuntime.java:4413)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:4520)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2619)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2601)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1543)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1013)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:430)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:339)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3665)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:820)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:934)
        ... 17 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function entries in object function Object() {
    [native code]
}. (https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js#2)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4396)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4374)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4407)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeErrorById(ScriptRuntime.java:4413)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:4520)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2619)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2601)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1543)
        at script.e(https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js:2)
        at script(https://developer.mozilla.org/static/js/2.6b2c0865.chunk.js:2)
        at script.f(https://developer.mozilla.org/static/js/runtime-main.930f84d6.js:1)
        at script(https://developer.mozilla.org/static/js/main.e9dd68ce.chunk.js:1)
        at script.f(https://developer.mozilla.org/static/js/runtime-main.930f84d6.js:1)
        at script.r(https://developer.mozilla.org/static/js/runtime-main.930f84d6.js:1)
        at script.t(https://developer.mozilla.org/static/js/runtime-main.930f84d6.js:1)
        at script(https://developer.mozilla.org/static/js/main.e9dd68ce.chunk.js:1)
        at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1013)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:430)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:339)
        at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3665)
        at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:820)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:934)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:650)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:540)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:353)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:829)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:805)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:110)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1022)
        at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:196)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.executeDeferredScriptsIfNeeded(HtmlPage.java:1474)
        at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:259)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:677)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:559)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:474)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:521)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:502)
        at rpvs.WebScraping.main(WebScraping.java:88)
======= EXCEPTION END ========

这是我的源代码

import java.io.IOException;
import com.gargoylesoftware.htmlunit.browserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;



public class WebScraping {
    public static void main(String[] args) throws IOException {
        
        WebClient webClient = new WebClient(browserVersion.BEST_SUPPORTED);

        webClient.getoptions().setJavaScriptEnabled(true);
        webClient.getoptions().setCssEnabled(false);
        webClient.getoptions().setUseInsecureSSL(true);

        HtmlPage page = webClient.getPage("https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies");

        String pageText = page.asnormalizedText();
        if(pageText != null){
            pageText = pageText.toLowerCase();

            System.out.println(pageText);
        }
      
        webClient.close();
    }

}

我不知道是什么导致了错误以及如何解决它。

解决方法

目前的 Rhino 实现看起来有问题。幸运的是,Rhino 的开发取得了一些进展 - 您缺少的功能似乎正在开发中 (https://github.com/mozilla/rhino/pull/902)

一旦它登陆 Rhino,我将更新 core-js 并提供一个新的快照。请查看 Twitter (https://twitter.com/htmlunit) 以了解更新。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...