0
當using Beautiful Soup to access a meta tag結果呈現爲整個標籤的「內容」屬性:訪問「說明」 meta標籤的
一個會如何解析結果只得到了content
屬性的內容?
當using Beautiful Soup to access a meta tag結果呈現爲整個標籤的「內容」屬性:訪問「說明」 meta標籤的
一個會如何解析結果只得到了content
屬性的內容?
根據文檔,.find()
返回可以訪問其密鑰的對象。
嘗試:
tag = soup.find(attrs={"name":"description"})
content = tag['content']
注意這僅返回第一個匹配的標籤。如果您需要所有匹配的標籤,請使用.findall()
,該標籤返回標籤列表。
以下是有關感興趣的文檔中特定部分的鏈接:http://www.crummy.com/software/BeautifulSoup/bs4/doc/#attributes – TerryA
謝謝,完美! – dotancohen