I like to use the following method. You can make the .replace('<br>','\r\n') manual in a string before passing it to strip_tags(html) to honor new lines.
From this question :
from HTMLParser import HTMLParser class MLStripper(HTMLParser): def __init__(self): self.reset() self.fed = [] def handle_data(self, d): self.fed.append(d) def get_data(self): return ''.join(self.fed) def strip_tags(html): s = MLStripper() s.feed(html) return s.get_data()
source share