我正在尝试解析http://www.ted.com/talks http://www.ted.com/talks所有演讲名称的页面。使用 BeautifulSoup,这是我所拥有的:
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']
最初的“链接”显示了一个由八个视频组成的漂亮数组。然后,我尝试使用上面的代码来完成此操作并取出标签中的标题,这给了我以下错误:
for anchor in link.findAll('a', title=True):
AttributeError: 'ResultSet' object has no attribute 'findAll'
我究竟做错了什么?
link
是一个集合Tag
对象,您需要对其进行迭代。例如:
for anchor in link:
print anchor['title']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)