PhilDpt PhilDpt - 2 years ago 102
HTML Question

Get text from span using Jsoup (java)

Hello I would like to get the value following "cotation" but I don't know how to do it.

<span id="brs-sl57350199c5a53">
<span class="cotation">16.33 (c)</span>

I'm using Jsoup and this my code:

Document doc = Jsoup.connect("").get();

Element loginform = doc.getElementById("content"); //brs-sl5734ff406037d
Elements inputElements = loginform.getElementsByTag("span");

for (Element inputElement : inputElements) {
String key = inputElement.attr("class");
System.out.println("Param name: "+ key);

And this is what I have:

Param name: cotation

Do you have any idea to be able to get the value instead of "cotation"?

Thanks in advance.

Answer Source

Add this in your loop :

if ("cotation".equals(key)) {

And you will get :

16.33 (c)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download