次の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.