我有以下 html 代码
<ol>
<li>If someone is <b>able</b> to do something, they <a href="/wiki/can" title="can">can</a> do it.
<dl>
<dd><i>I'm busy today, so I won't be <b>able</b> to see you.</i></dd>
</dl>
</li>
</ol>
如何提取<li>
和<dl>
标签之间的文本。
我试过这个:
from bs4 import BeautifulSoup
s = """<ol>
<li>If someone is <b>able</b> to do something, they <a href="/wiki/can" title="can">can</a> do it.
<dl>
<dd><i>I'm busy today, so I won't be <b>able</b> to see you.</i></dd>
</dl>
</li>
</ol>
"""
soup = BeautifulSoup(s)
for line in soup.find_all('ol'):
print line.li.get_text()
这将打印
If someone is able to do something, they can do it.
I'm busy today, so I won't be able to see you.
我只想要第一行。
If someone is able to do something, they can do it.