Created
August 22, 2012 07:06
-
-
Save 1900/3423220 to your computer and use it in GitHub Desktop.
feedparser test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import required modules | |
import feedparser, MySQLdb | |
# set up connection to MySQL database | |
db = MySQLdb.connect(host='host',user='user',passwd='pass',db='dbname') | |
cursor=db.cursor() | |
# fetch feed and turn into feedparser object | |
d = feedparser.parse('http://65s.org/feed/') | |
# determine number of entries in feed, which is used in processing loop | |
x = len(d.entries) | |
# processing loop - for each entry, selects certain attributes and inserts them into a MySQL table. Also converts the RSS entry date into a MySQL date | |
for i in range(x): | |
d2 = d.entries[i].description | |
cursor.execute("""INSERT INTO test (title, description, url) VALUES (%s,%s,%s)""", (d.entries[i].title, d.entries[i].description, d.entries[i].link)) | |
# commit insertions to table (optional) | |
db.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment