2016-06-21 11 views
1

"Amend"という単語を含む表の行(tr)要素を削除します。これを実現するには、以下のコードをどのように変更できますか?BeautifulSoupを使用してテキストコンテンツに応じて要素を削除します

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

+0

何TRとの修正、そこにはありません[修正] ' –

+0

tr要素の1つに「修正」という用語を持つ子があります。申し訳ありませんが、これを指定する必要があります。 –

答えて

1

どのようにあなたについて、Amendを持つすべてのノードを見つけるtrup the treeを行って、削除します。

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() 
+0

あなたの考えは好きですが、うまくいかない:これは私が取り組んでいるページです:https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=AAON&type=10&dateb=&owner=exclude&count = 40 –

+0

非常に感謝しています –

関連する問題