例如:
<p> Hello</p>
<div>hgello</div>
<pre>
code
code
<pre>
变成这样:
<p> Hello</p><div>hgello</div><pre>
code
code
<pre>
在python中如何做到这一点?我还大量使用
标记,因此用“”替换所有“\n”不是一个选项。
最好的办法是什么?最佳答案
您可以使用
re.sub(">\s*<","><","[here your html string]")
。
可能string.replace(">\n",">")
,即寻找一个封闭的括号和换行符并删除换行符。关于python - 在python中的html中删除标签之间的空格和换行符(aka取消格式化),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3093802/