时间:2021-07-01 10:21:17 帮助过:16人阅读
按题主给出的html,可以这样:
Document document = Jsoup.parse(html);
Elements elements = document.select("td br:lt(4)");
for (Element element : elements) {
System.out.println(element.previousSibling());
}
应题主需求,可以改为:
Document document = Jsoup.parse(html);
Elements elements = document.select("td");
for (Element element : elements) {
Elements brs = element.select("br:lt(4)");
if(StringUtils.isNotBlank(brs.toString()))
for (Element br : brs) {
System.out.print(br.previousSibling().toString().concat(" "));
}
else
System.out.println(element.html());
}