BeautifulSoup - 的findAll不能确定标签内 [英] BeautifulSoup - findAll not within certain tag

查看:157
本文介绍了BeautifulSoup - 的findAll不能确定标签内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图找到一种方法来找到有一定的标记,是不是某些其他标签内的BeautifulSoup对象中的所有项目。例如:

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> 

我想找到类=dayContainer,这是很简单的,但是如何的所有迭代我去寻找所有这些是不首先在类=diabled

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"?

推荐答案

运行标签的.parent不具有类属性的过滤器。类似

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']]

这篇关于BeautifulSoup - 的findAll不能确定标签内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆