簡體   English   中英

如何使用Jsoup從跨度獲取內容

[英]How to get content from span with Jsoup

我正在使用Jsoup HTML解析器從HTML頁面提取內容。

<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 one element
   Element elements = document.select("span[content]").first();
        System.out.println(elements.attr("content"));

如果您有多個相同跨度

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

輸出:68.00

在該“檢查JsoupSelector”上獲取參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM