[英]How can I detect outer Html tag of key in Html?
I fetch the HTML page source with retrofit and save it in String. 我获取了经过翻新的HTML页面源并将其保存在String中。 And i am searching for a key(Product Price) in this String.I can find the key in the String and how can I find the outer html tag or class that containing the key ? 我正在此String中搜索键(产品价格)。我可以在String中找到键,如何找到包含该键的外部html标签或类?
<input name="productPrice" id="productPrice" value="74.90"
type="hidden"/>
Simply in this HTML tag, I can find 74.90.
只需在此HTML标记中,我就可以找到74.90.
And how can I find the id or name? 以及如何找到ID或名称?
<div class="newPrice">
<ins content="3099.00">3.099,00 <span content="TRY">TL</span>
</ins><span class="kdv">KDV <br>DAHİL</span>
</div>
And this is another example. 这是另一个例子。 I can find 3099.00. 我可以找到3099.00。 And how can I find the div's class name? 以及如何找到div的类名?
I hope I can explain the problem 我希望我能解释这个问题
To get the class, select what you know - element ins
with attribute content
having value 3099.00
. 为了获取类,选择你所知道的-元素ins
与属性content
有值3099.00
。 Then select its parent and get the class of this parent. 然后选择其父级并获取该父级的类。
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class JsoupIssue57005455 {
public static void main(final String[] args) throws IOException {
String html = "<div class=\"newPrice\">"
+ " <ins content=\"3099.00\">3.099,00 <span content=\"TRY\">TL</span> "
+ " </ins><span class=\"kdv\">KDV <br>DAHİL</span>"
+ "</div>";
Document doc = Jsoup.parse(html);
System.out.println(doc.select("ins[content=3099.00]").first().parent().className());
}
}
output: newPrice
输出: newPrice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.