[英]BeautifulSoup - findAll not within certain tag
所以我試圖找到一種方法來查找BeautifulSoup對象中的所有項目,這些項目具有不在某個其他標記內的某個標記。 例如:
<td class="disabled first"> <div class="dayContainer">
<p class="day"> 29
</p> <p class="moreLink">
</p>
</div>
</td>
我想找到class="dayContainer"
所有迭代,這很簡單,但我如何找到所有那些不在class="diabled"
?
對.parent沒有該class屬性的標記運行過濾器。 就像是
filteredDayContainers = [tag for tag in soup.find_all('div',
attrs = {'class': 'dayContainer'})
if "disabled" not in tag.parent['class']]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.