java jsoup
阿神
阿神 2017-04-17 14:25:50
0
1
154
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 ?

阿神
阿神

闭关修行中......

모든 응답(1)
Ty80

用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.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!