How do I keep whitespace in BeautifulSoup.contents

后端 未结 1 1577
旧时难觅i
旧时难觅i 2020-12-19 23:23

Most examples I find online show how to remove whitespace - but in my case I need to keep it.. I have

html = \"I can flip this whole thing with one hand\\n          


        
相关标签:
1条回答
  • 2020-12-19 23:56

    The html parser seems to only keeps whitespace if the content you are parsing is in a <pre> tag -- in my case, the pre tag was removed. Adding

    html = "<pre>" + html + "</pre>"
    

    preserved the whitespace.

    0 讨论(0)
提交回复
热议问题