gpt4 book ai didi

java - 从 URL 中提取 HTML

转载 作者:太空狗 更新时间:2023-10-29 14:05:28 24 4
gpt4 key购买 nike

我正在使用 Boilerpipe使用此代码从 url 中提取文本:

URL url = new URL("http://www.example.com/some-location/index.html");
String text = ArticleExtractor.INSTANCE.getText(url);

字符串 text 只包含 html 页面的文本,但我需要从中提取整个 html 代码。

有没有人用过这个库并且知道如何提取 HTML 代码?

您可以查看 demo page有关图书馆的更多信息。

最佳答案

对于像这样简单的事情,你真的不需要外部库:

 URL url = new URL("http://www.google.com");
InputStream is = (InputStream) url.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
StringBuffer sb = new StringBuffer();
while((line = br.readLine()) != null){
sb.append(line);
}
String htmlContent = sb.toString();

关于java - 从 URL 中提取 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5213558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com