如何删除<;下的属性;p>;用正则表达式或python中的其他方式在html中标记?

如何删除<;下的属性;p>;用正则表达式或python中的其他方式在html中标记?,python,regex,python-3.x,beautifulsoup,Python,Regex,Python 3.x,Beautifulsoup,我使用此代码将和标记保留为字符串 from bs4 import BeautifulSoup mystring = 'aaa<p>Radio and<BR> television.<br></p><p align="right">very<br/> popular in the world today.</p><p class="myclass">Millions of people watch T

我使用此代码将

标记保留为字符串

from bs4 import BeautifulSoup

mystring = 'aaa<p>Radio and<BR> television.<br></p><p align="right">very<br/> popular in the world today.</p><p class="myclass">Millions of people watch TV. </p><p>That’s because a radio is very small <span style=":_black;">98.2%</span></p><p>and it‘s easy to carry. <span style=":_black;">haha100%</span></p>bb'
soup = BeautifulSoup(mystring,'html.parser')
for e in soup.find_all():
    if e.name not in ['p','br']:
        e.unwrap()
print(str(soup))
我想删除
标记下的属性

如何做到这一点?

你的意思是:

for e in soup.find_all():
    if e.name not in ['p','br']:
        e.unwrap()
    else:
        e.attrs={}
print(str(soup))
aaa<p>Radio and<br/> television.<br/></p><p>very<br> popular in the world today.</br></p><p>Millions of people watch TV. </p><p>That’s because a radio is very small 98.2%</p><p>and it‘s easy to carry. haha100%</p>bb
for e in soup.find_all():
    if e.name not in ['p','br']:
        e.unwrap()
    else:
        e.attrs={}
print(str(soup))