[英]How to get the specific information from an element in JSOUP?
我正在嘗試使用jsoup解析html文件。 這是我的代碼:
Document doc;
doc = Jsoup.connect("http://www.marketimyilmazlar.com/index.php?route=product/product&path=64_80&product_id=14102").get();
Elements elements = doc.getElementsByClass("price");
然后,當我查看elements變量時,其內容如下所示:
<div class="price">
2.75 TL
<span class="kdv">KDV Dahil</span>
<br />
</div>7
在這里,我想做的是,我想獲取值“ 2.75TL”。 我想到了使用elements.get(int index)方法,但是不知道如何使用索引變量。 誰能幫我這個?
謝謝
非常簡單,您需要從元素中取出文本節點,然后取其中的第一個,因此解決方案類似於:
element.textNodes().get(0);
您可以使用ownText方法,例如
Elements elements = doc.getElementsByClass("price");
System.out.println(elements.get(0).ownText()); // 2.75 TL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.