I'm attempting to use BeautifulSoup so get a list of HTML
tags, then check if they have a name attribute and then return that attribute value. Please see my code:
soup = BeautifulSoup(html) #assume html contains
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
My question is how do I get the value of the name attribute?
解决方案
Use the following code, it should work
nameTags = soup.findAll('div',{"name":True})
for n in nameTags:
# Do your processing