我試圖解析http://www.ted.com/talks頁會談的所有名稱。使用BeautifulSoup,這裏是我有:故障排除AttributeError的:「結果集」對象有沒有屬性「的findAll」
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'
我在做什麼錯?
這提供了以下錯誤:打印[ '標題' ] NameError:名稱 'A' 沒有定義 – EGP 2011-04-26 22:41:31
@Adam遺憾,這是一個錯字。現在修復。 – interjay 2011-04-26 22:42:53
看起來很迷人。謝謝!瞭解我可以在哪裏瞭解更多關於'錨'的語法?舉例來說:假設我想要的而不是標籤。我只想改變的findAll(「IMG」?只是好奇,瞭解更多信息。 – EGP 2011-04-26 23:55:40