首页 > 解决方案 > 无法为在客户端加载的网站获取 html

问题描述

我无法为客户端 html 加载获取/渲染 html,我尝试使用 HtmlUnit 和 Jsoup,但它们都不起作用。我只得到一个空白的html。

try (final WebClient webClient = new WebClient()) {
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setUseInsecureSSL(true);

    HtmlPage page = webClient.getPage(storeUrl);
    webClient.waitForBackgroundJavaScript(10000);

    System.out.println(page.asXml());
}

我在上面附上了我的代码。

<body>
    <div id="app">
    </div>
    <script type="text/javascript" src="https://appgallery5.huawei.com//static/2021092315/js/manifest.7678f8af2ad1888b12b7.js">
    </script>
    <script type="text/javascript" src="https://appgallery5.huawei.com//static/2021092315/js/vendor.4515fcb67725b83423f2.js">
    </script>
    <script type="text/javascript" src="https://appgallery5.huawei.com//static/2021092315/js/app.dffbd1139496dce7c98e.js">
    </script>
  </body>
</html>

以上是我得到的输出。我在这里做错了什么?

标签: javaweb-scrapingjsouphtmlunithtmlunit-driver

解决方案


推荐阅读