簡體   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