繁体   English   中英

带有OR和空类的BeautifulSoup FindAll

[英]BeautifulSoup FindAll with OR and Empty Class

我正在尝试提取以下内容:

<td class="indent">Interest Income on Fed. Funds</td>
<td class="">-</td>

有了这个

interest=a.findAll("td",{'class':[''|'indent']},limit=6)

但是,它返回

TypeError:|:'str'和'str'不支持的操作数类型

如何找到空类或class _ ='indent'?

尝试这个:

interest = a.findAll("td", {'class': [None, 'indent']}, limit=6)
  1. 将多个类作为列表传递(使用,分隔符不使用|
  2. 选择None空类

bs4的另一个选择:

def empty_or_indent(css_class):
    return css_class is None or css_class is 'indent'   

a.find_all('td', class_=empty_or_indent, limit=6)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM