【发布时间】:2021-03-25 02:23:16
【问题描述】:
我想提取/解析 HTML 页面的正文。为此,我使用 Jsoup API:https://jsoup.org/。
但是,我也想提取 CSS,但是当它在不同的文件夹中时该怎么做呢?
到目前为止,我的代码是在 tempFile 中编写页面的代码,所以我现在需要获取此页面的 CSS 以将其应用到此文件中:
public File parseHtml(String url) throws IOException {
Document doc = Jsoup.connect(url).get();
Element body = doc.body();
File tempFile = File.createTempFile(suffix, prefix);
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(body.outerHtml());
writer.close();
return tempFile;
}
【问题讨论】: