BeautifulSoup: How do I extract all the <li>s from a list of <ul>s that contains some nested <ul>s?
.findAll()
works for nested li
elements:
for ul in uls:
for li in ul.findAll('li'):
print(li)
Output:
<li>List items</li>
<li>Etc...</li>
<li>List items</li>
<li>Nested list items</li>
<li>Nested list items</li>
<li>List items</li>
A list comprehension could work, too.
lis = [li for ul in uls for li in ul.findAll('li')]