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

如何解决类型错误:在对象函数 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) 以了解更新。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?