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

I use this channel http://feeds.bbci.co.uk/news/rss.xml and want to get all media files: thumbnails. That is, 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 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, there is information, but how can I get it?

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

+3
source share
2 answers

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
+3
source

This works just as well, especially if you want the image 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
source

Source: https://habr.com/ru/post/1782199/


All Articles