gpt4 book ai didi

python - 故障排除 AttributeError : 'ResultSet' object has no attribute 'findAll'

转载 作者:太空宇宙 更新时间:2023-11-04 01:40:18 25 4
gpt4 key购买 nike

我正在尝试解析 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']

最初的“链接”显示了一个包含八个视频 block 的漂亮数组。然后我尝试使用上面的代码完成这个并取出标签中的标题,这给了我以下错误:

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

我做错了什么?

最佳答案

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

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

关于python - 故障排除 AttributeError : 'ResultSet' object has no attribute 'findAll' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5797233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com