从汤BeautifulSoup / Python的拆卸span标签 [英] Removing span tags from soup BeautifulSoup/Python
本文介绍了从汤BeautifulSoup / Python的拆卸span标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个Python汤:
I have a soup in Python like this:
<p>
<span style="text-decoration: underline; color: #3366ff;">
Title:
</span>
Info
</p>
<p>
<span style="color: #3366ff;">
<span style="text-decoration: underline;">
Title2:
</span>
</span>
Info2
</p>
我想获得它看起来是这样的:
I'd like to get it to look like this:
<p>
Title:
Info
</p>
<p>
Title2:
Info2
</p>
有没有办法与BS4做到这一点?
Is there a way to do this with bs4?
推荐答案
您会想要使用beautifulsoup的的展开()这一点。
You'll be wanting to use beautifulsoup's unwrap() for this.
import bs4
soup1 = bs4.BeautifulSoup(htm1, 'html.parser')
for match in soup1.findAll('span'):
match.unwrap()
print soup1
这篇关于从汤BeautifulSoup / Python的拆卸span标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文