« Easy Fix: Mysql InnoDB: Database was not shut down normally | Home | Full Source To Instant RSS Portals Using Django »
All You Need For Parsing RSS Feeds
By Paul Kenjora | February 5, 2008
I’m working on a a few applications to extend the Arkayne API and I needed a simple and easy to use RSS feed parser. It needed to tackle two issues:
- Parsing any feed (or as many as possible).
- Parsing any encoding (or as many as possible).
Granted one is solved by the parser while the other will probably fall to some clever code using Python’s built in encoding support.
The solutions I strongly recommend are:
The above two sources gave me all I needed to be able to parse the feeds I wanted. Biggest plus for me is that the Universal Feed Parser is a simple "feedparser.py" file. Donwloading is easy and no install is necessary, just add it to your PYTHONPATH. The resulting code will probably look something like this:
import feedparser
channels = feedparser.parse(feed.url)
url = ''
summary = ''
title = ''
for entry in channels.entries:
try:
url = unicode(entry.link, channels.encoding)
summary = unicode(entry.description, channels.encoding)
title = unicode(entry.title, channels.encoding)
except:
url = entry.link
summary = entry.description
title = entry.title
print "URL: ", url
print "Summary: ", summary
print "Title: ", title
Thats the simplest example. Of course there are many more fields that can be accessed. For more details on the Universal Feed Parser see the home page: http://www.feedparser.org
More from Aware Labs
- Constructive reasons to use Django instead of Rails (Proxied)
- Using Django Models In Batch Jobs
- Contact
- Add P2P Social Bookmarking To Your Pages
- Full Source To Instant RSS Portals Using Django
Aware Labs Recommends
- Why you should try Django : Agility (Dougal Matthews)
- DB2 support for Django is coming (Antonio Cangiano)
- Popularizing Django — Or Reusable apps considered harmful. (USwaretech)
Topics: Batch Code, Code Snippets, Tutorial | Comments
-
anon_anon