htmlunit 播放列表下载抛出错误

问题描述

我正在尝试使用 Htmlunit2.50.0 下载 Youtube Playlist 个视频,以下是我的代码:

 WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            webClient.setCssErrorHandler(new SilentCssErrorHandler());
            webClient.setAjaxController(new NicelyResynchronizingAjaxController());
            webClient.getOptions().setCssEnabled(true);
            webClient.getOptions().setRedirectEnabled(false);
            webClient.getOptions().setAppletEnabled(false);
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setPopupBlockerEnabled(true);
            webClient.getOptions().setTimeout(10000);

       HtmlPage currentPage = webClient.getPage("https://www.youtube.com/watch?v=dD2EISBDjWM&list=PLr6-GrHUlVf_ZNmuQSXdS197Oyr1L9sPB");
  
         System.out.println(currentPage.asNormalizedText());
         webClient.close();

但我收到以下错误:

Jun 12,2021 1:35:35 AM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException
SEVERE: Error during JavaScript execution
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: identifier is a reserved word: class (https://www.youtube.com/s/desktop/3a32c481/jsbin/custom-elements-es5-adapter.vflset/custom-elements-es5-adapter.js#11)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:949)
        at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:598)
        at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:487)
        at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:353)
        at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:780)
        at com.gargoylesoftwa

如果我从那里获取当前页面,我可以迭代列表并单击每个项目进行下载,但它在当前页面本身抛出错误。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)