PhilDpt PhilDpt - 9 months ago 29
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.


Add this in your loop :

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

And you will get :

16.33 (c)