java jsoup
阿神
阿神 2017-04-17 14:25:50
0
1
153
public static void main(String[] args){
    try
     {

    String s="<html><p><p><p>a</p>b</p>c</p></html>";
    Document doc = Jsoup.parse(s);
    Elements p = doc.select("p");

    **String   text= p.get(1).text();**

    System.out.println(text);

     }catch (Exception e){       
     }
}

String text=p.get(0).text(); 结果显示: abc
String text=p.get(1).text(); 结果显示: ab
String text=p.get(2).text(); 结果显示: a

请问怎么能单独显示 b 或者 C ?

阿神
阿神

闭关修行中......

reply all(1)
Ty80

Using the ownText method can return the text content of the current element and will not return the text content of the child elements.

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!