开发者

How to get image from this BBC feed using Python and Universal Feed Parser

I am using this feed http://feeds.bbci.co.uk/news/rss.xml and want to get all media:thumbnail entries. I.e. all images


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

The entry has this in the 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"

So, the info is there, but how can I get it?

(I am using the latest feedparser version feedparser.version -> '4.2-pre-294-svn')


Using the latest SVN r354 I got this working:

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


This works just as well especially if you want the picture for each article in the feed:

d = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml')
for entry in d.entries:
    print(entry.media_thumbnail)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜