Reputation: 3150
I'm using htmlunit to get this webpage
https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
Maven dependency:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.49.1</version>
</dependency>
I'm getting the following error
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 ========
This is my source code:
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();
}
}
I don't know what is causing the error and how to resolve it.
Upvotes: 0
Views: 1576
Reputation: 2889
Looks like a problem with the current Rhino implementation. Luckily there is some progress on the Rhino development - the function you are missing seems to be on the way (https://github.com/mozilla/rhino/pull/902)
As soon as this has landed in Rhino i will update core-js and make a new snapshot available. Please check twitter (https://twitter.com/htmlunit) to get informed about updates.
Upvotes: 1