gpt4 book ai didi

python - BeautifulSoup 连接单词

转载 作者:行者123 更新时间:2023-12-01 05:43:49 25 4
gpt4 key购买 nike

>>> BeautifulSoup('<span>this is a</span>cat').text
u'this is acat'
>>> BeautifulSoup('Spelled f<b>o</b>etus in British English with extra "o"').text
u'Spelled foetus in British English with extra "o"'

标记标签之间的一些解析需要在它们之间留有空格(就像acat)。确保解析器将空格放在有意义的地方的好方法是什么?我正在尝试将电子邮件转换为文本。

最佳答案

根据评论进行编辑:

BeautifulSoup 支持第一个示例。您所要做的就是

BeautifulSoup('<span>this is a</span>cat').get_text(" ")

它将使用空格连接两个元素之间的文本。据记录here

关于python - BeautifulSoup 连接单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16767405/

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