Was making a parser recently with BeautifulSoup. Came to the final with rendering contents of the edited text. Like so:
text = "<h1>Test text tag</h1>" soup = BeautifulSoup(text, "html5") text = soup.renderContents() print text
'<html><head></head><body><h1>Test text tag</h1></body></html>'
The workaround is simple enough:
text = soup.body.renderContents()
Result is:
text = '<h1>Test text tag</h1>'
Comments
Post a Comment