views:

626

answers:

6

Hello, I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?

+4  A: 

http://www.feedparser.org/

First hit on G.

piotr
Well, he did mention it in the question...
Max Shawabkeh
Anyway, Do you guys have any idea about other than feedpurser which is easy to use?
rahman.bd
@rahman.bd no, feedparser is too good, nobody would care about an alternative.
THC4k
Feedparser is an awesome library. It has loads of unit tests, and it comes with a wonderful built in library that helps with character encoding detection. It's truly a work of art.
Brad Wright
+1  A: 

In answer to your followup. You could use BeautifulSoup - but feedparser is much better geared towards RSS handing.

Not to snark - but have you read feedparsers documentation? I don't know how it could be simpler to use.

ZenGyro
A: 

If you want an alternative, try xml.dom.minidom. Like "Django is Python", "RSS is XML".

myfreeweb
No good reason to take this approach when feedparser exists. You'd have to handle differences between RSS and Atom, malformed feeds, various date/timestamp formats, etc.
FogleBird
+3  A: 

Feedparser is very powerful, configurable and sooo easy to use. A very friendly learning curve, if at all.

Example

Programatically determine how many answers your question has:

easy_install feedparser
python -c 'import feedparser; print len(feedparser.parse("http://bit.ly/c785aj")["entries"])'
flybywire
You can use .entries instead of ["entries"] since feedparser uses a customized dictionary that allows attribute access. Easier to type and read.
FogleBird
+6  A: 

Using feedparser is a much better option than rolling your own with minidom or BeautifulSoup.

  • It normalizes the differences between all versions of RSS and Atom so you don't have to have different code for each type.
  • It's good about detecting different date formats and other variations in feeds.
  • It automatically follows HTTP redirects.
  • It sanitizes HTML content.
  • It has support for ETag and Last-Modified headers so you can see if the feed has changed just by downloading the HTTP header and not the whole feed.
  • It has support for authenticated feeds.
  • It has support for HTTP proxies.

Like others have mentioned, just try it. It's like 2 lines of code to parse a feed. My only complaint is that it just uses dictionaries as its data model and some attributes can be missing from the dictionary if they weren't in the feed, so you have to check for that in your code. But the documentation is very clear on which attributes will always be in the dictionary and which might be missing.

Finally, I can vouch for it, as I've written an application that uses it. See here: http://www.feednotifier.com/

FogleBird
Thanks for your answer!..Yes it is so cool and well defined documentation!..easy to use.!! Your feed notifier is also interesting though!
rahman.bd
Do you know of a library that takes feedparser's output and can turn it back into a feed?
St3fan
A: 

I Strongly recommend feedparser.

flybywire