Hello. There is a page, example:

<div> <div></div>(1) <div> <div></div>(2) </div>(3) </div> 

I selected the first div element. How do I get items 1 and 3, while ignoring 2?

  • Does the root element have any identifier? - Alexey Shimansky
  • <div class = "content main"> - Alexander
  • Elements resultDivs = doc.select("div.content.main" > div"); will not work? - Alexey Shimansky
  • No, unfortunately in this case, he will allocate all descendants, but I need only the descendants of the first level - Alexander
  • Yes, it can not be. It is precisely the immediate descendants that chooses without nesting - Aleksey Shimansky

1 answer 1

 final Stream<Element> stream = doc.getElementsByTag("div").stream(); stream.forEach(element -> { //проверка на контекст }