为什么得到“ TypeError:const e的重新声明”用HtmlUnit抓取时?

问题描述

我想使用live Bitcoin price抓取HtmlUnit。我正在运行以下代码获取网站的内容,但出现错误

private void htmlUnit() {

    String START_URL = "https://www.Tradingview.com/symbols/BTCUSDT/?exchange=BINANCE";
    try {
        WebClient webClient = new WebClient(browserVersion.CHROME);
        webClient.getoptions().setJavaScriptEnabled(true);
        webClient.getoptions().setCssEnabled(false);
        webClient.waitForBackgroundJavaScript(10000);
        HtmlPage page = webClient.getPage(START_URL);
        System.out.println();
    } catch (IOException ex) {
        ex.printstacktrace();
    }

}

我得到的异常:

      com.gargoylesoftware.htmlunit.ScriptException: TypeError: redeclaration of const e. (https://www.Tradingview.com/static/bundles/category.1bca33621fc200171fb7.js#145)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:883) [htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:714) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:680) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:103) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1102) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:982) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:362) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:236) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:792) [htmlunit-2.36.0.jar:2.36.0]
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(UnkNown Source) [xercesImpl-2.12.0.jar:na]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:748) [htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1175) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1115) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:303) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3146) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2074) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:922) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:438) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:389) [neko-htmlunit-2.36.0.jar:2.36.0]
    at org.apache.xerces.parsers.XMLParser.parse(UnkNown Source) [xercesImpl-2.12.0.jar:na]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:991) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:246) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:190) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:534) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450) [htmlunit-2.36.0.jar:2.36.0]
    at simplespringbootapp.demo.DemoApplication.htmlUnit(DemoApplication.java:64) [classes/:na]
    at simplespringbootapp.demo.DemoApplication.run(DemoApplication.java:47) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at simplespringbootapp.demo.DemoApplication.main(DemoApplication.java:37) [classes/:na]
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: TypeError: redeclaration of const e. (https://www.Tradingview.com/static/bundles/category.1bca33621fc200171fb7.js#145)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$HtmlUnitErrorReporter.error(HtmlUnitContextFactory.java:420) ~[htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:259) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:235) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.definesymbol(Parser.java:2273) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.variables(Parser.java:2172) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1225) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statements(Parser.java:1090) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.block(Parser.java:1994) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1249) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.getNextStatementAfterInlineComments(Parser.java:1496) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.forLoop(Parser.java:1607) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1198) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statements(Parser.java:1090) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.block(Parser.java:1994) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1249) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.getNextStatementAfterInlineComments(Parser.java:1496) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.ifStatement(Parser.java:1327) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1186) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parseFunctionBody(Parser.java:772) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.function(Parser.java:942) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3119) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2366) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2322) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.nameOrLabel(Parser.java:2071) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1271) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parseFunctionBody(Parser.java:772) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.function(Parser.java:942) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3119) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.plainProperty(Parser.java:3715) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.objectLiteral(Parser.java:3615) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3127) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.arrayLiteral(Parser.java:3318) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3123) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.argumentList(Parser.java:2718) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExprTail(Parser.java:2868) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2787) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2322) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1281) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:672) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:593) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.parse(Context.java:2642) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2588) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1582) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:222) ~[htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1571) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.doRun(JavaScriptEngine.java:705) ~[htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:868) [htmlunit-2.36.0.jar:2.36.0]
    ... 42 common frames omitted

解决方法

我写了HTML Scraping的软件。我的工具用于生成外国新闻服务的翻译。提及这一点是为了解释此答案中的背景信息-,因此您可能会了解 HTML Scrape 的位置最有用,以及何时最好避免使用它(并且可能效率低下,没有必要的“种类”。

在提供REST API的情况下,使用 REST API 几乎总是“明智的”。 Wikipedia上有关REST API的文章包含以下复制(剪切和粘贴)的描述。我见过或读到的几乎所有REST都提供 JSON 作为对 web-server query 的回应。

遵守REST体系结构约束的Web服务API是 称为RESTful API。[14]基于HTTP的RESTful API是使用 以下几个方面:[15]

  • 基本URI,例如http://api.example.com/collection/;标准HTTP方法(例如GET,POST,PUT,PATCH和DELETE);
  • 定义状态转换数据元素的媒体类型(例如Atom,微格式,application / vnd.collection + json,[15]:91–99等)。
  • 当前表示形式告诉客户端如何组成转换到所有下一个可用应用程序状态的请求。这个 可以像URI一样简单,也可以像Java小程序一样复杂。[16]

通常了解如何使用JSON API要求使用Java可以使用的两个不同的JSON解析器之一。其中一个埋在 javax.json 包层次结构树中,另一个埋在 android.JSON 开发平台包中。两种方法都可以帮助您解析对REST API的响应,与尝试在装有Java Script的网站上运行Java Script相比,几乎总是更好的

这里是JSON解析的文档站点-Java再次有两个被广泛使用:

我之所以提到HTML解析器,正是因为我试图解释在某些情况下 获取所需数据的唯一方法 是通过 { {1}} (甚至执行Java脚本),但是,当向“ Internet整体”提供实际的API时,最好使用这些API。

在Google上进行的快速搜索显示,有数十个 HTML Parsing 用于BitCoin Traders-并尝试使用我提到的JSON库之一解析这些响应会更聪明。这些链接是通过在 REST API's

中输入“ BitCount REST API”直接复制的

您尝试使用 Google Search Bar 抓取的页面是其中之一 我已经看到了更复杂的Java脚本/ AJAX加载页面。它可能 Selenium 很难轻松执行该脚本。我有 我一生中多次犯错,但我想我建议使用 Selenium 的比特币价格

,

您或多或少地遇到了此错误,因为HtmlUnit使用的js引擎与当前浏览器的js并非100%兼容。 引擎在各个版本之间都得到了改进,但仍有很多工作要做。

或更技术性的-看一下这个js文件https://www.tradingview.com/static/bundles/category.1bca33621fc200171fb7.js。这段代码中的某处是错误的原因。...

您可以设置

stripTrailing()

让js引擎忽略错误并进一步处理js代码。

最后一点

webClient.getOptions().setThrowExceptionOnScriptError(false);

不是一个选择。页面检索后必须调用此名称。

您的代码应如下所示

webClient.waitForBackgroundJavaScript(10000);

希望这会有所帮助。并且请记住,至少图表是基于画布绘制的-意味着您可以使用asText()来获得此图。

相关问答

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