regex remove all html tags except br python 1

regex remove all html tags except br python

def cleanhtml(raw_html):
    cleanr = re.compile(r'<(?!br).*?>')
    cleantext = cleanr.sub('', raw_html)
    return cleantext

Here is what the above code is Doing:
1. We’re using the BeautifulSoup library to parse the HTML.
2. We’re using the findAll method to find all the

tags in the HTML.
3. We’re using the getText method to extract the text from the

tags.
4. We’re using the join method to join the paragraphs together.
5. We’re using the cleanhtml method to remove any HTML tags that are left.
6. We’re returning the text.

Similar Posts