Jes*_*ose 3 python beautifulsoup
>>> 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"'
Run Code Online (Sandbox Code Playgroud)
标记标签之间的一些解析需要在它们之间留有空格(就像那样acat)。确保解析器将空格放在有意义的地方的好方法是什么?我正在尝试将电子邮件转换为文本。
根据评论编辑:
BeautifulSoup 支持第一个示例。你所要做的就是
BeautifulSoup('<span>this is a</span>cat').get_text(" ")
Run Code Online (Sandbox Code Playgroud)
它将使用空格连接两个元素之间的文本。它记录在这里