2017-03-28 126 views
0

我正在使用Jsoup HTML解析器從HTML頁面提取內容。如何從Jsoup跨度獲取內容

<span class="mainPrice reduced_"> 
<span class="oPrice" data-test="preisArtikel"> 
<span itemprop="price" content="68.00"><span class="oPriceLeft">68</span><span    class="oPriceSeparator">,</span><span class="oPriceRight">00</span></span><span  class="oPriceSymbol oPriceSymbolRight">&euro;</span> 

我要提取的內容(68.00),我嘗試以下操作:

Elements price = doc.select("span.oPrice"); 
String priceString = price.text(); 

這並不是因爲類 「oPrice」 工作發生44次的頁面和字符串「priceString」包含44個不同的價格。

謝謝你的幫助。如果您有多個類似相同跨度

//For multiple 
    Elements elements = document.select("span[content]"); 
    for (Element element:elements){ 
     System.out.println(element.attr("content")); 
    } 

輸出

: 68.00

最重要的是檢查JsoupSelector爲參考

回答