使用cdp4j获取渲染后的网页

发布于 2019-05-31  66 次阅读


maven中添加依赖

    <dependency>
      <groupId>io.webfolder</groupId>
      <artifactId>cdp4j</artifactId>
      <version>2.2.1</version>
    </dependency>

样例

    private String getHtml(String url) {
        Launcher launcher = new Launcher();
        SessionFactory factory = launcher.launch();
        Session session = factory.create();
        session.navigate(url);
        session.waitDocumentReady();
        return session.getContent();
    }