我正在尝试刮掉这个块:
<b>Address:</b></br>
First Line</br>
Second Line</br>
City, State Zip</br>
<b>Phone: 718-555-2121</br>
<b>Fax:</b> 718-555-1212</br>
<b>Email:</b> ex@example.com</br>
可靠地进入字典。
dict = {
'address':'First Line\n Second Line\n City, State Zip\n',
'phone':'718-555-2121',
'Fax:':'718-555-1212',
'Email:':'ex@example.com',
}
如果我查找粗体,然后查找 next_sibling,我可以得到电话号码、传真和电子邮件,但地址是几个兄弟姐妹。
for nut in soup.find_all("b"):
print nut,
try:
print nut.next_sibling.tag
except:
print nut.next_sibling
如果我查找粗体,然后查找 next_siblings,我会得到所有兄弟姐妹:
for nut in soup.find_all("b"):
print nut
for s,sibling in enumerate(nut.next_siblings):
print s, (repr(sibling))
有没有一种干净的方式(while
?)说继续组装 next_siblings 直到你找到一个大胆的兄弟姐妹?