Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.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
Java 为什么要“得到”;类型错误:常数e的重新声明;用它刮的时候?_Java_Web Scraping_Htmlunit - Fatal编程技术网

Java 为什么要“得到”;类型错误:常数e的重新声明;用它刮的时候?

Java 为什么要“得到”;类型错误:常数e的重新声明;用它刮的时候?,java,web-scraping,htmlunit,Java,Web Scraping,Htmlunit,我想用刮刀刮。我正在运行下面的代码来获取网站的内容,但是得到了一个错误 private void htmlUnit() { String START_URL = "https://www.tradingview.com/symbols/BTCUSDT/?exchange=BINANCE"; try { WebClient webClient = new WebClient(BrowserVersion.CHROME); web

我想用刮刀刮。我正在运行下面的代码来获取网站的内容,但是得到了一个错误

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抓取软件。我的工具用于生成外国新闻服务的翻译。提到这一点是为了解释本答案中的背景信息,这样您就可以了解HTML Scrape最有用的地方,以及最好避免的时间(可能效率低下且“有点”不必要)

在提供了的情况下,使用RESTAPI几乎总是“明智的”。这篇关于RESTAPI的Wikipedia文章包含以下复制(剪切和粘贴)的描述。我所看到或读到的几乎所有其他内容都提供了
JSON
作为对
web服务器查询的响应

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

  • 基本URI,例如标准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
开发平台包中。任何一个都将帮助您解析对RESTAPI的响应,而这些响应几乎总是比尝试在充满Java脚本的网站上运行Java脚本要好

以下是JSON解析的文档站点——同样,Java有两个常用的站点:

  • (旧Java包)
  • (更新版,适用于Android)
我提到我使用的HTML解析器,正是因为我试图解释,在某些情况下,获取所需数据的唯一方法是通过
HTML解析(甚至Java脚本执行),然而,当实际的API提供给“整个互联网”时用这些来代替是更好的

在谷歌上快速搜索可以发现数十种比特币交易员使用的RESTAPI,而使用我提到的JSON库解析这些响应会更聪明。这些链接是通过将“BitCount REST API”输入谷歌搜索栏直接复制的

您试图使用Selenium刮取的页面是 我见过更复杂的Java脚本/AJAX页面。可能吧 Selenium很难轻松执行该脚本。我有 在我的一生中多次出错,但我想我可以建议使用 比特币价格的不同
网站URL


您或多或少会遇到这个错误,因为HtmlUnit使用的js引擎与当前浏览器的js不完全兼容。 引擎从一个版本改进到另一个版本,但仍有很多工作要做

或者更技术性的-看看这个js文件。此代码中的某个地方是错误的原因

你可以设置

webClient.getOptions().setThrowExceptionOnScriptError(false);
让js引擎忽略错误并进一步处理js代码

还有最后一点

webClient.waitForBackgroundJavaScript(10000);
这不是一种选择。您必须在页面检索之后调用此函数

您的代码应该如下所示

String url = "https://www.tradingview.com/symbols/BTCUSDT/?exchange=BINANCE";
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
    webClient.getOptions().setThrowExceptionOnScriptError(false);

    HtmlPage page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(20_000);

    System.out.println(" ---- ");
    System.out.println(page.asText());
    System.out.println(" ---- ");
}

希望这有帮助。请记住,至少图表是基于画布呈现的,这意味着您可以使用asText()实现这一点。

谢谢,我知道有很多付费API,比特币价格只是一个例子,还有其他类似这样的实时数据,我想从中获取,而且我没有使用我说过的
Selenium
,我正在使用
HtmlUnit