Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feedparser-basics how to

I'm very new to Feedparser and have returned to Python after a long break so would appreciate any help. I've tried the docs, which are very good, but I'm still slightly lagging.

How would I get Feedparser to take an rss feed and from that get the title and description of the first 10 items and label each item independently so that they can be inserted anywhere into other code? ie. I could just use the title of the first and second items with descriptions from others?

Hope that makes sense! Any help much appreciated

like image 451
James Wanchai Avatar asked Feb 24 '10 13:02

James Wanchai


People also ask

How to use Feed Parser Python?

You start your program with importing the feedparser module. Create the feed. Put in the RSS feed that you want. The items are available in d.

What does Feed Parser parse do?

Universal Feed Parser is a Python module for downloading and parsing syndicated feeds. It can handle RSS 0.90, Netscape RSS 0.91, Userland RSS 0.91, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0, and CDF feeds.

Which tool is used to install Feed Parser in the system?

The best method for installing FeedParser (or almost any Python package) is by using pip , Python's package manager. pip will be installed by default alongside Python as of Python 3.4 (and Python 2.7. 9).


1 Answers

import feedparser
f = feedparser.parse('http://domain/feed')
# f contains a dictionary key 'entries'
# entries is a list of dictionaries with 'title' and 'content' keys
for e in f['entries']:
    print e.get('title', '')
    print e.get('summary', '')

Hope that helps.

like image 79
Kurt McKee Avatar answered Oct 12 '22 22:10

Kurt McKee