2024-04-26 13:56:51 发布
网友
我有一个字符串中有“代码”标记,我想删除这些标记和这些标记内的所有内容。例如
"hello how are <code>this is my code</code> you"
变成
我很确定BeautifulSoup是这项工作的正确工具,但是我已经看过文档,我不知道如何做到这一点。在
谢谢
轻松使用Tag.extract():
Tag.extract()
>>> from bs4 import BeautifulSoup as BS >>> s = "hello how are <code>this is my code</code> you" >>> soup = BS(s) >>> codetags = soup.find_all('code') >>> for codetag in codetags: ... codetag.extract() >>> print soup hello how are you
轻松使用
Tag.extract()
:相关问题 更多 >
编程相关推荐