How do I keep whitespace in BeautifulSoup.contents

后端 未结 1 1582
旧时难觅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

     tag -- in my case, the pre tag was removed. Adding

    html = "
    " + html + "
    "

    preserved the whitespace.

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