带标签python
发布时间:2020-12-15 08:06:38 所属栏目:Python 来源:互联网
导读:我想要以下功能. input : this is test b bold text /b normal textexpected output: this is test normal text 即删除指定标签的内容 使用BeautifulSoup的解决方案: from BeautifulSoup import BeautifulSoupdef removeTag(soup, tagn
我想要以下功能. input : this is test <b> bold text </b> normal text expected output: this is test normal text 即删除指定标签的内容 解决方法使用BeautifulSoup的解决方案:from BeautifulSoup import BeautifulSoup def removeTag(soup,tagname): for tag in soup.findAll(tagname): contents = tag.contents parent = tag.parent tag.extract() s = BeautifulSoup("abcd <b> btag </b> hello <d>dtag</d>") removeTag(s,"b") print s removeTag(s,"d") print s 收益: >>> abcd hello <d>dtag</d> abcd hello (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – 如何复制一个估计器,以便在多个数据集上使用它?
- 如何在docutils中使用null
- python – 计算两个numpy数组之间相交值的有效方法
- python – 如何在没有带有pandas的“未命名”行的情况下读取
- python – Selenium’WebElement’对象没有属性’Get_Attri
- 解密Python中的描述符(descriptor)
- python – 启动py.test后,在读取请求的数据流后无法访问正文
- 用于__str__和方法解析顺序的Python Mixin
- python – 使用numpy将alpha通道添加到RGB数组
- 我如何确定python使用的类型的确切大小