AttributeError 故障排除:“ResultSet"对象没有“findAll"属性 [英] Troubleshooting AttributeError: 'ResultSet' object has no attribute 'findAll'
本文介绍了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'
我做错了什么?
推荐答案
link
是 Tag
对象的集合,您需要对其进行迭代.例如:
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屋!
查看全文