如何使用Python和Universal Feed Parser从这个BBC Feed中获取图像

时间:2010-12-26 21:25:05

标签: python feeds feedparser

我正在使用此Feed http://feeds.bbci.co.uk/news/rss.xml并想要获取所有媒体:缩略图条目。即所有图片


   import feedparser
   d = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml')
   e = d['entries'][0]
   print e.media_thumbnail ## this returns ''

条目在rss中有这个:



      media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/50560000/jpg/_50560468_50557389.jpg"
      media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/50581000/jpg/_50581208_010904244-1.jpg"

所以,信息就在那里,但我怎么能得到它?

(我使用的是最新的feedparser版本feedparser。版本 - >'4.2-pre-294-svn')

2 个答案:

答案 0 :(得分:3)

使用最新的SVN r354我得到了这个工作:

>>> e = d['entries'][0]
>>> print e["media_thumbnail"][0]["url"]
http://news.bbcimg.co.uk/media/images/50560000/jpg/_50560468_50557389.jpg

答案 1 :(得分:0)

这也很有效,特别是如果你想要饲料中每篇文章的图片:

def __str__(self):
    out = ['\nTeam name is ' + self.teamName]
    out.append('Their regular season record was ' + self.record)
    out.append('Their win streak is ' + self.winStreak)
    out.append('Their scoring percentage is ' + self.scoringPercentage)
    out.append('Their average rebounds are ' + self.rebounds)
    out.append('Their passing is ' + self.passing)
    out.append('Their turnovers are ' + self.turnovers)
    return '\n'.join(out)