【发布时间】:2020-02-22 06:24:25
【问题描述】:
我需要解析以下文本并为每个文本创建单独的对象。我尝试了几种方法,但它没有以我需要的格式提供结果。
正文是:
String text = "This is start of a text <a href=\"https://google.com/sample\">followed by a link sample</a>and ending with some text."
使用下面的代码:
Document document = Jsoup.parse(text);
Elements elements = document.select("*");
for(Element e : elements){
System.out.println( e.tagName() + ": " + e.text());}
实际结果是
root: This is start of a text followed by a link sampleand ending with some text.
html: This is start of a text followed by a link sampleand ending with some text.
head:
body: This is start of a text followed by a link sampleand ending with some text.
p: This is start of a text followed by a link sampleand ending with some text.
a: followed by a link sample
我需要得到以下结果,以便为每个文本创建一个自定义对象
body: This is start of a text
a:followed by a link sample
body:and ending with some text.
【问题讨论】:
标签: jsoup html-parsing