Reputation: 36317
I have the following html from a table with alternating light and dark rows:
<tr class="light">
<td>....
</td>
</tr>
<tr class="dark">
<td>....
I can get either all the light or all dark rows using:
soup.select('tr.light') or soup.select('tr.dark')
Is there a way to combine both in a single statement?
Upvotes: 1
Views: 439
Reputation: 29710
Beautiful soup supports CSS selectors, so it should just allow you to use grouping.
If it does, then you could just select both via:
soup.select('tr.dark, tr.light') # note the comma between.
EDIT: Beautiful soup seems to have rather limited CSS selector support, so alternatively you could try this:
import re
soup.find_all("td" class_=re.compile("light|dark"))
Another alternative is that lxml is supposed to support the full range of CSS selectors.
Upvotes: 1