I am working on a project where I have to be able to know that an element have repeated children .For example in that DOM, I want to know that the element tbody
has similar children
My goal is to extract data- and store it in a database -from pages that I ignore their structure.
you can use JSOUP for this. its very easy to use as well
for example you want to get all td
tag in within your document:
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:
to get all elements you can do:
for(Element e : doc.getAllElements){
System.out.println(e.getTagName());//prints the tag name
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.