2012-09-17 34 views
1
<div id="studentInfo"> 
<p id="studentdetails"> 
<span>Placeofbirth:</span> 
    <span class="hidden" itemtype="http://xxxx.com" itemscope=""> 
    <a itemprop="url" href="xxx.xom"> 
    <span itemprop="title">Greg</span> 
    </a> 
    <span itemtype="http://xxxx1.com" itemscope="" itemprop="child"> 
    <a itemprop="url" href="/c/san-diego/indpak"> 
<span itemprop="title">Greg is one of the Best student</span> 
</a> 
</span> 
</span> 
<span id="cat_display"> 
<a href="xxx.com"> Greg can be promoted </a> 
</span> 

我做了jsoup得到一個特定的值

Element studentname = doc.select("div p ").first(); 

當我這樣做:我正在 格雷格·格雷格是最好的學生格雷格可以促進之一。

我只想打印:當我做p 格雷格可以促進

看起來,並嘗試打印studentname.text() 它打印所有目前的案文,我一直在尋找一個特定的文本。

我該如何實現這一點。

回答

1

希望這是您的解決方案

Elements students = document.select("div p #cat_display"); 
System.out.println(students.text()); 
0

這是更好的解決方案和更快

String sText= document.select("span#cat_display").text(); 
System.out.println(sText);