获取一个标签之外和另一个标签内的文本

mur*_*d99 5 python beautifulsoup html-parsing

我正在使用BeautifulSoup解析一个网页,它有一些如下所示的元素:

<td><font size="2" color="#00009c"><b>Consultant Registration Number  :</b></font>  16043646</td>
Run Code Online (Sandbox Code Playgroud)

结构总是似乎是<td>第一部分被包围<font><b>,并且</font>标签之后的文本可以是空的.如何获取字体标记之后的文本?

在这个例子中,我想得到"16043646".如果是html而已

<td><font size="2" color="#00009c"><b>Consultant Registration Number  :</b></font></td>
Run Code Online (Sandbox Code Playgroud)

我想得到 ""

Sha*_*hin 5

>>> from BeautifulSoup import BeautifulSoup
>>> text1 = '<td><font size="2" color="#00009c"><b>Consultant Registration Number  :</b></font>  16043646</td>'
>>> text2 = '<td><font size="2" color="#00009c"><b>Consultant Registration Number  :</b></font></td>'
>>> BeautifulSoup(text1).td.font.nextSibling
u'  16043646'
>>> BeautifulSoup(text2).td.font.nextSibling
>>>
Run Code Online (Sandbox Code Playgroud)