Wordpress RSS Feed Parsing



Feedparser, wordpress & python

This stuff is really easy!

import feedparser

def get_feed(url):
    feed = feedparser.parse(url)
    msg = '\nFound {} posts from {}\n'.format(len(feed['entries']), feed['feed']['title'])
    print(msg)
    return feed

rss = get_feed('http://ruthlessbarber.co.uk/rss')

for post in rss['entries']:
    print(post['title'])

The full json for a single post looks like this.

{
  'title': 'Fridge Magnets',
  'title_detail': {
    'type': 'text/plain',
    'language': None,
    'base': 'http://ruthlessbarber.co.uk/feed/',
    'value': 'Fridge Magnets'
  },
  'links': [{
    'rel': 'alternate',
    'type': 'text/html',
    'href': 'https://ruthlessbarber.co.uk/fridge-magnets/'
  }],
  'link': 'https://ruthlessbarber.co.uk/fridge-magnets/',
  'comments': 'https://ruthlessbarber.co.uk/fridge-magnets/#respond',
  'published': 'Fri, 07 Dec 2018 10:09:13 +0000',
  'published_parsed': time.struct_time(tm_year = 2018, tm_mon = 12, tm_mday = 7, tm_hour = 10, tm_min = 9, tm_sec = 13, tm_wday = 4, tm_yday = 341, tm_isdst = 0),
  'authors': [{
    'name': 'Redbeard'
  }],
  'author': 'Redbeard',
  'author_detail': {
    'name': 'Redbeard'
  },
  'tags': [{
    'term': 'Tales',
    'scheme': None,
    'label': None
  }, {
    'term': 'Fridge magnets',
    'scheme': None,
    'label': None
  }, {
    'term': 'Mindfulness',
    'scheme': None,
    'label': None
  }, {
    'term': 'Travels',
    'scheme': None,
    'label': None
  }],
  'id': 'https://ruthlessbarber.co.uk/?p=504',
  'guidislink': False,
  'summary': '<p>Its a cold December morning in North England. Again. As I’m stood blearily stirring my cup of tea, I happen to glance at myfridge which is covered in magnets. Looking at it warms me, clears my thoughts and makes me smile. As some of you may know, I’ve recently [&#8230;]</p>\n<p>The post <a rel='nofollow' href='https://ruthlessbarber.co.uk/fridge-magnets/'>Fridge Magnets</a> appeared first on <a rel='nofollow' href='https://ruthlessbarber.co.uk'>Ruthless Barber</a>.</p>',
  'summary_detail': {
    'type': 'text/html',
    'language': None,
    'base': 'http://ruthlessbarber.co.uk/feed/',
    'value': '<p>Its a cold December morning in North England. Again. As I’m stood blearily stirring my cup of tea, I happen to glance at my fridge whichis covered in magnets. Looking at it warms me, clears my thoughts and makes me smile. As some of youmay know, I’ve recently [&#8230;]</p>\n<p>The post <a rel='nofollow' href='https://ruthlessbarber.co.uk/fridge-magnets/'>Fridge Magnets</a> appeared first on <a rel='nofollow' href='https://ruthlessbarber.co.uk'>Ruthless Barber</a>.</p>'
  },
  'wfw_commentrss': 'https://ruthlessbarber.co.uk/fridge-magnets/feed/',
  'slash_comments': '0'
}

Thanks for reading. x

Resources