我正在尝试使用 BeautifulSoup 所以得到一个 HTML 列表 <div>
标签,然后检查它们是否具有名称属性,然后返回该属性值。请看我的代码:
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
我的问题是如何获取名称属性的值?
最佳答案
使用下面的代码,它应该可以工作
nameTags = soup.findAll('div',{"name":True})
for n in nameTags:
# Do your processing
关于python - 获取标签列表,获取BeautifulSoup中的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10797741/