python - 如何删除 beautifulsoup 中的换行符?

标签 python beautifulsoup python-requests

<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/

相关文章:

python - 如果网站的响应返回 XML/JSON,我如何从该网站下载信息?

javascript - Python3 - 我不想用 BeautifulSoup 打印 Javascript 代码

python - 如何从 "class"HTML 标签中查找文本匹配?

python - 我可以使用 BeautifulSoup 删除脚本标签吗?

python - scikit-learn:预期是二维数组,却得到了一维数组

python - 类型错误(不可排序的类型 : int() <= NoneType())

python - 在 "for"循环中一个一个添加数组元素?

python - future session : socket connections not closed

python - 同时引发两个错误

Python请求模块Put问题