Skip to content Skip to sidebar Skip to footer

Beautifulsoup And  

My Code: html = ' ' from bs4 import BeautifulSoup print BeautifulSoup(html).renderContents() The output: ┬á Desired outp

Solution 1:

Use encode_contents instead of renderContents, or encode or prettify. They all support the formatter argument, and pass 'html' as formatter:

html = "<tag>&nbsp;</tag>"from bs4 import BeautifulSoup
print BeautifulSoup(html).encode_contents(formatter='html')

produces:

<tag>&nbsp;</tag>

Post a Comment for "Beautifulsoup And  "