相关疑难解决方法(0)

使用BeautifulSoup删除标记但保留其内容

目前我的代码执行如下操作:

soup = BeautifulSoup(value)

for tag in soup.findAll(True):
    if tag.name not in VALID_TAGS:
        tag.extract()
soup.renderContents()
Run Code Online (Sandbox Code Playgroud)

除了我不想丢弃无效标签内的内容.如何在删除标签但在调用soup.renderContents()时保留内容?

python beautifulsoup

48
推荐指数
6
解决办法
5万
查看次数

标签 统计

beautifulsoup ×1

python ×1