Я попробовал это, чтобы найти, является ли таблица вложенной.
// Nested Tables
Elements table = doc.getElementsByTag("table");
table.traverse(new NodeVisitor() {
public void head(Node node, int x) {
if (!(node instanceof TextNode)) {
System.out.println(node.childNodes());
if (node.childNodes().contains("<table>")) {
tables++;
}
}
}
public void tail(Node node, int x) {
}
});
// Nested Tables
Любые идеи, как заставить его работать?
Пытаться:
int nTables = 0;
Elements tables = doc.getElementsByTag("table");
for(Element table : tables) {
for(Element child : table.children()) {
Elements nestedTables = child.getElementsByTag("table");
if(!nestedTables.isEmpty()) {
nTables++;
}
}
}
Или просто попробуйте doc.select("table table").size()
. Селектор проверяет наличие второго тега таблицы над дочерними тегами. Поэтому он дает количество табличных тегов по меньшей мере с одной дочерней таблицей.