Created
October 7, 2014 19:58
-
-
Save wololock/621a42546cac6dd0daa2 to your computer and use it in GitHub Desktop.
Jsoup select nested li example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jsoup.Jsoup | |
import org.jsoup.nodes.Document | |
@Grab(group='org.jsoup', module='jsoup', version='1.8.1') | |
def html = ''' | |
<div id="something"> | |
<ul> | |
<li>First element</li> | |
<li> | |
<ul> | |
<li>Nested li #1</li> | |
<li>Nested li #2</li> | |
</ul> | |
</li> | |
<li> | |
<span>Third element</span> | |
</li> | |
</ul> | |
</div> | |
''' | |
Document document = Jsoup.parse(html) | |
assert document.select('#something > ul > li').size() == 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment