Louis Etienne
Louis Etienne

Reputation: 1371

remove del tag with BeautifulSoup

I have a little stupid problem with BeautifulSoup and Python3. This is my HTML :

<span id="gaixm--1521602--15686128--ADHP.GEO_LONG" Visibility="None">
        <del class="cellChanged NO_REVISION_MARK AmdtDeletedAIRAC" title="Date d'entrée en vigueur: 17 SEP 2015. " id="geaip_4b6c6e3f-9841-400c-9359-6ae9b334448d">001°49'57"E</del>
        <ins class="cellChanged AmdtInsertedAIRAC" title="Date d'entrée en vigueur: 17 SEP 2015. " id="geaip_311221e8-2de7-4fce-b261-e0e9fb988238">001°49'52"E</ins>
</span>

I want to remove all the del tag. But when I do :

soup = BeautifulSoup(html, 'lxml')
soup.del.decompose()
tbody_tag = soup.table.tbody
print(tbody_tag)

I have an error (and it's normal, del it's a python name..) :

  File "algo.py", line 52
    soup.del.decompose()
           ^
SyntaxError: invalid syntax.

So... How can I do this ?
Thanks for your help !

Upvotes: 1

Views: 743

Answers (1)

adray
adray

Reputation: 1448

You can use findAll function and then delete all results

for d in soup.findAll('del'):
  d.decompose()

Upvotes: 3

Related Questions