java jsoup
public static void main(String[] args){
try
{
String s="<html><div><div><div>a</div>b</div>c</div></html>";
Document doc = Jsoup.parse(s);
Elements div = doc.select("div");
**String text= div.get(1).text();**
System.out.println(text);
}catch (Exception e){
}
}
String text=div.get(0).text(); 结果显示: abc
String text=div.get(1).text(); 结果显示: ab
String text=div.get(2).text(); 结果显示: a
请问怎么能单独显示 b 或者 C ?
绮丽的梦境
9 years, 10 months ago
Answers
用ownText方法,可以指返回当前元素的文本内容,不会返回子元素的文本内容。
public String ownText()
Gets the text owned by this element only; does not get the combined text of all children.
For example, given HTML
Hello there now!
, p.ownText() returns "Hello now!", whereas p.text() returns "Hello there now!". Note that the text within the b element is not returned, as it is not a direct child of the p element.
专食葱的人
answered 9 years, 10 months ago