我刚刚发现了美丽的汤,这似乎很强大。我想知道是否有一种简单的方法来提取文本“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木管乐器
但我想有字符提取,这将使
其中管弦乐队的不同部分内中高音场,你会发现:
小提琴的琴弦
在小号黄铜
甲单簧管和萨克斯在木管乐器
由于
看一看:http://stackoverflow.com/questions/2612548/extracting -an-attribute-value-with-beautifulsoup – JacobIRR