使用Jsoup从跨度获取文本(java)
问题描述:
你好,我想获得“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”?
在此先感谢。
答
在循环补充一点:
if ("cotation".equals(key)) {
System.out.println(inputElement.html());
}
,你会得到:
16.33 (c)
谢谢你,这是我需要的到底是什么! – PhilDpt