使用 BeautifulSoup 根据文本内容删除元素

Remove elements according to text content using BeautifulSoup

我想删除包含单词 "Amend" 的 table 行 (tr) 元素。我怎样才能更改下面的代码来实现这一点?

for e in soup.findAll("tr"):
   e.extract()

*** 编辑:

我试过以下方法都无济于事:

for e in soup.findAll('tr', text = re.compile('.*Amend.*')):
    e.extract()

*** 编辑:

这是我正在处理的页面:

https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=AAON&type=10&dateb=&owner=exclude&count=40

如何找到所有具有 Amend 的节点,转到 up the treetr 并删除:

for amend in soup.find_all(text=re.compile("Amend")):
    tr = amend.find_parent("tr")
    if tr:  # safety feature
        tr.extract()

或者,您也可以使用 searching function:

for tr in soup.find_all(lambda node: node and \
                                     node.name == "tr" and \
                                     node.find(text=re.compile("Amend"))):
    tr.extract()