【发布时间】:2015-02-07 18:38:04
【问题描述】:
我正在尝试使用 BeautifulSoup 更改 html 文件的内容。此内容将来自基于 python 的文本,因此它将有 \n 换行符...
newContent = """This is my content \n with a line break."""
newContent = newContent.replace("\n", "<br>")
htmlFile.find_all("div", "product").p.string = newContent
当我这样做时,html 文件 <p> 文本更改为:
This is my content <br> with a line break.
如何更改 BeautifulSoup 对象中的字符串并保持<br> 中断?如果字符串只包含\n,那么它将创建一个实际的换行符。
【问题讨论】:
标签: python html beautifulsoup