[英]Remove html tags with their contents using Python
There is any option to remove html tags WITH their content?有什么选项可以删除 html 标签及其内容?
I only found strip tags functions that keep text inside tags.我只找到了将文本保留在标签内的条形标签功能。
I want remove tags and their contents .我想删除标签及其内容。
Ex: "Teste: <b> oi</b> nome"
will be "Teste: nome"
例如:
"Teste: <b> oi</b> nome"
将是"Teste: nome"
Thanks.谢谢。
You can try regex to achieve it.您可以尝试正则表达式来实现它。
import re
s = "Teste: <b> oi</b> nome"
replaced = re.sub('<.*?>.*?</.*?>', '', s)
print(replaced)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.