So I'm trying to find a way to find all items within a BeautifulSoup object that have a certain tag that aren't within a certain other tag. For example:
<td class="disabled first"> <div class="dayContainer">
<p class="day"> 29
</p> <p class="moreLink">
</p>
</div>
</td>
I want to find all iterations of class="dayContainer"
, which is simple enough, but how do I go about finding all of those that aren't first within class="diabled"
?
Run a filter for tags whose .parent doesn't have that class attribute. Something like
filteredDayContainers = [tag for tag in soup.find_all('div',
attrs = {'class': 'dayContainer'})
if "disabled" not in tag.parent['class']]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With