故障排除AttributeError:"ResultSet"对象没有属性"findAll" [英] Troubleshooting AttributeError: 'ResultSet' object has no attribute 'findAll'

查看:555
本文介绍了故障排除AttributeError:"ResultSet"对象没有属性"findAll"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析 http://www.ted.com/talks 页面谈话的所有名称.使用BeautifulSoup,这是我所拥有的:

I'm trying to parse the http://www.ted.com/talks page for all the names of the talk. Using BeautifulSoup, here is what I have:

import urllib2

from BeautifulSoup import BeautifulSoup

page = urllib2.urlopen("http://www.ted.com/talks")

soup = BeautifulSoup(page)

link = soup.findAll(lambda tag: tag.name == 'a' and tag.findParent('dt', 'thumbnail'))

for anchor in link.findAll('a', title = True):
    print anchor['title']

最初的链接"显示了一个很好的阵列,其中包含八个视频块.然后,我尝试使用上面的代码仔细检查并删除标签中的标题,这给了我以下错误:

The initial "link" displays a nice array of the block of eight videos there. I then try to go through this and take out the titles in the tags, using the above code, which gives me the following error:

for anchor in link.findAll('a', title=True):
AttributeError: 'ResultSet' object has no attribute 'findAll'

我在做什么错了?

推荐答案

linkTag对象的集合,您需要对其进行迭代.例如:

link is a collection of Tag objects, which you need to iterate over. For example:

for anchor in link:
    print anchor['title']

这篇关于故障排除AttributeError:"ResultSet"对象没有属性"findAll"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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