[英]How to compare children of an element in a DOM with jsoup
我在一個項目中必須知道一個元素有重復的子代,例如在那個DOM中,我想知道元素tbody
具有相似的子代
我的目標是從我忽略其結構的頁面中提取數據並將其存儲在數據庫中。
您可以為此使用JSOUP 。 它也非常易於使用
例如,您要在文檔中獲取所有td
標簽:
String html=... //your html string
Document doc = JSoup.parse(html);
Elements elements = doc.select("tbody").select("td");
System.out.println(elements.size()); //prints number of td within tbody REGARDLESS of where in the DOM tree they live.
EDIT1:
獲得所有您可以做的元素:
for(Element e : doc.getAllElements){
System.out.println(e.getTagName());//prints the tag name
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.