我非常困惑。我有一块 HTML 是我从一个更大的表格中刮下来的。它看起来像这样:
<td align="left" class="page">Number:\xc2\xa0<a class="topmenu" href="http://www.example.com/whatever.asp?search=724461">724461</a> Date:\xc2\xa01/1/1999 Amount:\xc2\xa0$2.50 <br/>Person:<br/><a class="topmenu" href="http://www.example.com/whatever.asp?search=LAST&searchfn=FIRST">LAST,\xc2\xa0FIRST </a> </td>
(实际上,它看起来更糟,但我正则表达式掉了很多换行符)
我需要把这些线弄出来,把日期/金额线分开。开始的地方似乎是找到那个 HTML 块的孩子。该块是一个字符串,因为这就是正则表达式将它还给我的方式。所以我做了:
text_soup = BeautifulSoup(text)
text_children = text_soup.find('td').childGenerator()
我可以遍历孩子
for i,each in enumerate(text_soup.find('td').childGenerator()):
print type(each)
print i, ":", each
但不与
for i, each in enumerate(text_children):
...etc
这些应该是一样的。所以我很困惑。