因此,我试图找到一种方法来查找 BeautifulSoup 对象中具有某个标签但不在某个其他标签内的所有项目。例如:
<td class="disabled first"> <div class="dayContainer">
<p class="day"> 29
</p> <p class="moreLink">
</p>
</div>
</td>
我想找到所有迭代class="dayContainer"
,这很简单,但是我如何找到所有不在其中的第一个class="diabled"
?
对 .parent 不具有该类属性的标签运行过滤器。就像是
filteredDayContainers = [tag for tag in soup.find_all('div',
attrs = {'class': 'dayContainer'})
if "disabled" not in tag.parent['class']]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)