gpt4 book ai didi

python - 如何使用 Beautifulsoup 在一些文本中嵌入 p 标签?

转载 作者:行者123 更新时间:2023-11-28 22:08:01 25 4
gpt4 key购买 nike

我想嵌入 <p > 在有\r\n\r\n 的地方标记。

u“斯里兰卡终于出现了,阻止了他们的第一个 5-0 系列粉饰,并阻止了印度连续九次 ODI 胜利。\r\n\r\n对于 62 个球,Yuvraj Singh 打出了梦幻般的敲击,保持了印度在比赛中,尽管小门在他周围掉落。\r\n\r\n也许抛球起了很大作用。这只是 Mahela Jayawardene 在过去 11 次中第二次用硬币击败 Mahendra Singh Dhoni。\r\n\r\n正是 Jayasuriya 为斯里兰卡提供了跳板。\r\n\r\n烟火可能在 Jayasuriya 被解雇后停止了,但跑动继续以公平的速度进行。"

我尝试使用 BeautifulSoup 解决此问题,但找不到解决方法。任何人都可以对此有所了解。提前致谢。

最佳答案

''.join('<p>%s</p>' % line for line in text.split('\r\n\r\n'))
# Results:
u"<p>Finally Sri Lanka showed up, prevented their first 5-0
series whitewash, and stopped India at nine ODI wins in a row. </p>
<p>For 62 balls Yuvraj Singh played a dream knock, keeping India in the
game despite wickets falling around him. </p><p>Perhaps the toss played
a big part. This was only the second time Mahela Jayawardene beat Mahendra
Singh Dhoni with the coin in the last 11 occasions. </p>
<p>It was Jayasuriya who provided Sri Lanka with the springboard. </p>
<p>The pyrotechnics may have stopped upon Jayasuriya's dismissal, but
the runs kept coming at a fair pace.</p>"

关于python - 如何使用 Beautifulsoup 在一些文本中嵌入 p 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/527629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com