I'm trying to convert a chunk of HTML text with BeautifulSoup. Here is an example:
<div>
<p>
Some text
<span>more text</span>
even more text
</p>
<ul>
<li>list item</li>
<li>yet another list item</li>
</ul>
</div>
<p>Some other text</p>
<ul>
<li>list item</li>
<li>yet another list item</li>
</ul>
I tried doing something like:
def parse_text(contents_string)
Newlines = re.compile(r'[\r\n]\s+')
bs = BeautifulSoup.BeautifulSoup(contents_string, convertEntities=BeautifulSoup.BeautifulSoup.HTML_ENTITIES)
txt = bs.getText('\n')
return Newlines.sub('\n', txt)
...but that way my span element is always on a new line. This is of course a simple example. Is there a way to get the text in the HTML page as the way it will be rendered in the browser (no css rules required, just the regular way div, span, li, etc. elements are rendered) in Python?