1

I'm using Java Jsoup to get some details.

<ul class="vcard-details"> 
 <li class="vcard-detail" itemprop="homeLocation"><span class="octicon octicon-location"></span>Caldwell, Idaho, USA</li> 
 <li class="vcard-detail"><span class="octicon octicon-mail"></span><a class="email" href="mailto:jamisbuck@gmail.com">jamisbuck@gmail.com</a></li> 
 <li class="vcard-detail" itemprop="url"><span class="octicon octicon-link"></span><a href="http://blog.jamisbuck.org" class="url" rel="nofollow me">http://blog.jamisbuck.org</a></li> 
 <li class="vcard-detail"><span class="octicon octicon-clock"></span><span class="join-label">Joined on </span><time class="join-date" datetime="2008-02-28T17:37:32Z" day="numeric" is="local-time" month="short" year="numeric" title="Feb 28, 2008, 11:07 PM GMT+5:30">Feb 28, 2008</time></li> 
</ul>

I've got the above section using..

Element bio = doc.getElementsByClass("vcard-details").first();

Is there any way I can get the text 'Caldwell, Idaho, USA' ? I'm trying to make use of class name 'octicon octicon-location', because I need to get all those attributes seperatly (only if they are available).

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Krishnalal P
  • 487
  • 4
  • 20
  • Take a look at http://stackoverflow.com/questions/21336845/how-to-parse-ul-li-tags-using-jsoup-in-android - It has example of getting the text from LI tag (with a SPAN in it). – Avi L Nov 18 '14 at 07:08

3 Answers3

1

The Span with the class you want to use contains no value, since it's closed before the text 'Caldwell, Idaho, Usa' is in the document. To access to contents of the li tag you can use the code below. You can then manipulate the string to get rid of the Span tag.

var value = document.querySelector('li.vcard-detail').innerHTML;
Roy Wasse
  • 390
  • 1
  • 10
1

Using jsoup's selector syntax:

Element first = doc.select("ul.vcard-details > li.vcard-detail").first();
System.out.println(first.text());

Output:

Caldwell, Idaho, USA

Is there any way I can get the text

Yes: text().

ollo
  • 24,797
  • 14
  • 106
  • 155
0

you ccan use below code

document.getElementsByClassName("vcard-detail")[0].innerHTML).split("</span>")[1]