去除指定标签
复制代码
1
2
3
4
5
6
7from bs4 import BeautifulSoup #去除属性ul [s.extract() for s in soup("ul")] # 去除属性svg [s.extract() for s in soup("svg")] # 去除属性script [s.extract() for s in soup("script")]
去除注释
复制代码
1
2
3
4
5from bs4 import BeautifulSoup, Comment #去除注释 comments = soup.findAll(text=lambda text: isinstance(text, Comment)) [comment.extract() for comment in comments]
最后
以上就是强健大米最近收集整理的关于利用BeautifulSoup去除HTML指定标签和去除注释去除指定标签去除注释的全部内容,更多相关利用BeautifulSoup去除HTML指定标签和去除注释去除指定标签去除注释内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复