如何使用JSOUP获取标签的内容

时间:2019-07-16 12:45:45

标签: android css-selectors jsoup

我有这样的HTML代码:

<div class="newPrice">
    <ins content="1857.00">1.857,00 <span content="TRY">TL</span></ins><span class="kdv">KDV <br>DAHİL</span>
</div>

我想获得1857.00(而不是1.857,00)。我该怎么办?

我尝试了

Elements den = doc.select(":containsOwn("1.857,00")");

它返回

<ins content="1857.00">1.857,00 <span content="TRY">TL</span></ins>

我不能再走了

谢谢。

2 个答案:

答案 0 :(得分:0)

我解决了这个问题。如果我说:

String price = den.attr("content");

它返回1857.00

答案 1 :(得分:0)

理想的方法是这样:

Element ele = doc.select("div.newPrice ins").first();
String price = ele.attr("content");
System.out.println(price);

如果我们使用 .text(),它将写出CSS路径中存在的所有文本,

当涉及属性时,我们必须使用 .attr()来获取所需的值。

相关问题