我获取经过改进的HTML页面源代码,并将其保存在String中。我在这个字符串中搜索一个键(Product Price)。我可以在这个字符串中找到这个键,我怎样才能找到包含这个键的外部html标记或类呢?
<input name="productPrice" id="productPrice" value="74.90"
type="hidden"/>
只需在这个HTML标记中,我就可以找到74.90.
,我如何才能找到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>
这是另一个例子。我能找到3099.00。怎样才能找到div的类名呢?
我希望我能解释这个问题。
发布于 2019-07-16 03:08:13
要获取这个类,请选择您所知道的内容--属性为content
且值为3099.00
的元素ins
。然后选择它的父对象并获取该父对象的类。
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());
}
}
输出:newPrice
https://stackoverflow.com/questions/57005455
复制相似问题