<p>
First line of output.<br\>
This is the second line.<br\>
</p>
使用 bs.find('p').text
我得到以下输出:
First line of output.
This is the second line.
我想删除
标签,并且我想获得类似于 第一行输出的输出。这是第二行。
我尝试用空格替换 \n
、\r\n
但没有任何改变。怎么解决呢?
最佳答案
您只需对字符串运行“替换”即可。
s = "<p>First line of output.<br\>This is the second line.<br\></p>"
s.replace("<br\>", "")
将删除所有标签“
”,然后对同一字符串运行replace("\n", "")
关于python - 如何删除 beautifulsoup 中的换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63901337/