python3 从字符串中剥离or替换html标签
- 方法一
单纯替换,不适用于标签多且杂的字符串
data = "<p>Hello,</p>"
data = data .replace('</p>', '').replace('<p>', '')
print(data)
>>>
Hello,
- 方法二
要处理大量的HTML / XML
from bs4 import BeautifulSoup
data = "<p>Hello,</p><br/><p>"
soup = BeautifulSoup(data,features="html.parser")
data = soup.text
print(data)
>>>
Hello,