如何在Python中使用BeautifulSoup分离标记?

时间:2014-02-27 18:46:58

标签: python beautifulsoup

代码是:

<span><span class="rank_no">1</span>CONTENTS_HERE</span>

我如何获得CONTENTS_HERE

当我使用THE_STRING.find('span')时,结果会显示1

1 个答案:

答案 0 :(得分:4)

您可以使用next_sibling

>>> soup = BeautifulSoup('<span><span class="rank_no">1</span>CONTENTS_HERE</span>')
>>> soup.find('span').span.next_sibling
u'CONTENTS_HERE'