Skip to content

Instantly share code, notes, and snippets.

@wololock
Created October 7, 2014 19:58
Show Gist options
  • Save wololock/621a42546cac6dd0daa2 to your computer and use it in GitHub Desktop.
Save wololock/621a42546cac6dd0daa2 to your computer and use it in GitHub Desktop.
Jsoup select nested li example
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