How to remove HTML comments from a string in Python

1 Answer

0 votes
import re

html = """<p>Python <strong>programming language</strong></p><!-- comment -->"""

s = re.sub("<!--.*?-->", "", html)

print(s)


'''
run:
 
<p>Python <strong>programming language</strong></p>

'''

 



answered Nov 18, 2018 by avibootz
...