BeautifulSoup,得到的标签列表,并得到属性值 [英] BeautifulSoup, get a list of tags and get the attribute values

查看:723
本文介绍了BeautifulSoup,得到的标签列表,并得到属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用BeautifulSoup因此得到的HTML标签的列表,然后检查他们是否有一个名称属性,然后返回属性值。请参阅我的code:

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 <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属性的值?

My question is how do I get the value of the name attribute?

在此先感谢
露丝

Thanks in Advance Ruth

推荐答案

使用以下code,它应该工作

Use the following code, it should work

nameTags = soup.findAll('div',{"name":True})
for n in nameTags:
    # Do your processing

这篇关于BeautifulSoup,得到的标签列表,并得到属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆