とても美味しい美しいスープを発見しました。私はテキストがある "alt"フィールドを抽出する簡単な方法があるかどうか疑問に思っています。 簡単な例は、これはあなたが見つけるオーケストラの異なるセクションの中で美味しいスープで「alt」を抽出する方法
につながる
from bs4 import BeautifulSoup
html_doc ="""
<body>
<p>Among the different sections of the orchestra you will find:</p>
<p>A <img src="07fg03-violin.jpg" alt="violin" /> in the strings</p>
<p>A <img src="07fg03-trumpet.jpg" alt="trumpet" /> in the brass</p>
<p>A <img src="07fg03-woodwinds.jpg" alt="clarinet and saxophone"/> in the woodwinds</p>
</body>
"""
soup = BeautifulSoup(html_doc, 'html.parser')
print(soup.get_text())
次のようになります。
A真鍮
内の文字列Aで
木管内A
しかし、私はあなたが見つけるオーケストラの異なるセクションの中
を与えるテキスト抽出、内部の代替フィールドを持っているしたいと思います:文字列
でトランペットで
バイオリン真鍮
木管楽器でクラリネットとサックス
おかげ
をプリントアウト:http://stackoverflow.com/questions/2612548/extractingを-an-attribute-value-with-beautifulsoup(この質問の可能な複製) – JacobIRR