[英]BeautifulSoup FindAll with OR and Empty Class
I am trying to extract the following: 我正在尝试提取以下内容:
<td class="indent">Interest Income on Fed. Funds</td>
<td class="">-</td>
with this 有了这个
interest=a.findAll("td",{'class':[''|'indent']},limit=6)
However, it returns 但是,它返回
TypeError: unsupported operand type(s) for |: 'str' and 'str'
TypeError:|:'str'和'str'不支持的操作数类型
How could I find empty class OR class_='indent'? 如何找到空类或class _ ='indent'?
Try this: 尝试这个:
interest = a.findAll("td", {'class': [None, 'indent']}, limit=6)
,
separator not with |
) ,
分隔符不使用|
) None
None
空类 Another option as well for bs4: 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.