Java 如何从HTML代码中获取值?
我有以下代码:Java 如何从HTML代码中获取值?,java,jsoup,Java,Jsoup,我有以下代码: <div id="g4iloprop"> <h4>HF propagation conditions: <span class="date">2012 Sep 19 1205 UTC</span></h4> <p><b><span title="10.7cm solar flux">Solar flux:</span></b> 104<img src="n
<div id="g4iloprop">
<h4>HF propagation conditions: <span class="date">2012 Sep 19 1205 UTC</span></h4>
<p><b><span title="10.7cm solar flux">Solar flux:</span></b> 104<img src="nc.gif" alt="no change" hspace="2" /> <b><span title="Mid-latitude A Index">A:</span></b> 8<img
高频传播条件:2012年9月19日1205 UTC
太阳通量:104 A:8试试这个:
String html = // your html here
Document doc = Jsoup.parse(html);
Elements elements = doc.select("b + img");
for( Element e : elements )
{
Node value = e.previousSibling();
// eg. print the node, here the output is 104 and 8
System.out.println(value.toString());
}
如果只需要第一个值,可以使用以下内容替换for循环:
Node value = elements.first().previousSibling();