2016-05-12 53 views
1

你好,我想獲得「cotation」後面的值,但我不知道該怎麼做。使用Jsoup從跨度獲取文本(java)

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

我使用Jsoup這我的代碼:

Document doc = Jsoup.connect("http://www.boursorama.com/bourse/actions/cours_az.phtml").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); 
} 

這就是我:

Param name: cotation 

你有什麼想法能夠得到的價值而不是「cotation」?

在此先感謝。

回答

1

在循環補充一點:

if ("cotation".equals(key)) { 
    System.out.println(inputElement.html()); 
} 

,你會得到:

16.33 (c) 
+1

謝謝你,這是我需要的到底是什麼! – PhilDpt