2012-09-19 28 views
0

我有這樣的代碼:如何從HTML代碼中獲取價值?

<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 

提示請給我拿值104是標籤之間</b> 104<img

感謝。

回答

2

試試這個:

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();