简体   繁体   English

jsoup获得特定值

[英]jsoup getting a particular value

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

I did a 我做了一个

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

when I do :I am getting Greg Greg is one of the Best student Greg can be promoted . 当我这样做时:我正在获取Greg Greg是最好的学生之一,可以提升Greg。

I want to print only: Greg can be promoted 我只想打印:可以提升Greg

Looks when I do p, and try to print studentname.text() it is printing all the text present, I was looking for one particular Text. 查看当我执行p时,并尝试打印studentname.text(),它正在打印存在的所有文本,我正在寻找一个特定的Text。

How can I acheieve this. 我该如何做到这一点。

Hope This is your Solution 希望这是您的解决方案

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

This is the better solution and quicker 这是更好的解决方案,速度更快

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM