Python/BeautifulSoup - 如何从元素中删除所有标签? [英] Python/BeautifulSoup - how to remove all tags from an element?

查看:46
本文介绍了Python/BeautifulSoup - 如何从元素中删除所有标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何简单地从在 BeautifulSoup 中找到的元素中去除所有标签?

How can I simply strip all tags from an element I find in BeautifulSoup?

推荐答案

随着 BeautifulStoneSoupbs4 中消失,它在 Python3 中更加简单

With BeautifulStoneSoup gone in bs4, it's even simpler in Python3

from bs4 import BeautifulSoup

soup = BeautifulSoup(html)
text = soup.get_text()
print(text)

这篇关于Python/BeautifulSoup - 如何从元素中删除所有标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆