我試圖使用BeautifulSoup,所以得到一個HTML標籤列表,然後檢查他們是否有一個名稱屬性,然後返回該屬性值。請參閱我的代碼:BeautifulSoup,獲取標籤列表並獲取屬性值
soup = BeautifulSoup(html) #assume html contains <div> tags with a name attribute
nameTags = soup.findAll('name')
for n in nameTags:
if n.has_key('name'):
#get the value of the name attribute
我的問題是如何獲取name屬性的值?
由於提前 露絲
謝謝Ramesh,您的上述代碼可以工作,但我想知道如何獲取屬性的值 – Ruth