Answers
按题主给出的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());
}
醉拳甘乃迪
answered 11 years, 7 months ago