开发者

How can I select the divs elements that not having another divs inside it?

I'm using Java and Jsoup to parse HTML pages and I want to get all the divs that not contains another divs inside it to print the text it contains.

But for example, if a div contains a table, and the table costains a div, I don't want it. I want onl开发者_StackOverflow中文版y the div at the most bottom level, with none another div inside it (another tags are ok).

How I do this?

Primarilly, I want to know if there is some syntax that can I use with the select() method.


Document doc; //comes as parameter

Elements divs = doc.getElementsByTag("div");
for(Element div: divs){
    if(div.getElementsByTag("div").size() == 1){
        //is a div with no divs inside it
    }
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜