2012-09-17 90 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);