#100DaysOfCode in Python Transcripts
Chapter: Days 52-54: Parsing RSS feeds with Feedparser
Lecture: Concepts: what did we learn
0:00 And that's it, I told you it was simple.
0:02 So Feedparser is awesome.
0:05 A very, very simple and small lightweight thing to use
0:09 but really helps you out if you want to automate things
0:12 like feeds.
0:13 So, let's just recap quickly what we did without going
0:16 into too much detail.
0:18 We import requests and this is for pulling down
0:21 the XML feed.
0:23 Specify the feed that we want to pull down, okay.
0:27 We actually get the feed using that URL
0:31 and we store it in r.
0:35 We then open a file, you can call this whatever you want,
0:38 and then we write the contents of that XML file,
0:44 that feed, into
0:46 the file that you specified there, okay.
0:52 And now, onto the Feedparser stuff.
0:55 So obviously the first thing we do
0:57 is import feedparser.
1:01 Then we specify that actual file that we created
1:05 in the last step.
1:06 Okay, remember we separated these two processes of pulling
1:10 the file and then parsing it just in case you had
1:13 a scenario where, let's say you couldn't pull the file.
1:17 Well, if you couldn't pull it, at least you have
1:19 an existing file and you can continue parsing that.
1:21 The whole thing doesn't fall over, alright.
1:24 Now we parse it using feedparser.parse and throw that
1:29 into the feed, all right.
1:31 And then we have the little sanity check there to make
1:33 sure the feed is okay to parse,
1:35 that it has that title tag that we want
1:38 and that we did necessary again.
1:40 You can wrap some sort of a try except or whatever
1:44 you know, error checking you want around that.
1:48 Then for every entry within that feed we're going to take
1:52 the data stored against publish in the publish tag,
1:56 in the title tag and the link tag and then we're going to
1:59 print that in a nice little string
2:02 and that's it, okay.
2:04 Now, very exciting.
2:07 It's your turn.
2:08 So for the next day I would like you,
2:11 instead of printing out that data,
2:14 so in the previous step you saw we printed out
2:16 the publish, the title and the link.
2:20 Instead of printing it out,
2:22 why not do something interesting with it?
2:24 What can you think that you might be able to do with it?
2:26 So just some ideas, maybe you could e-mail that data
2:31 which is exactly what I'm doing with this steam stuff.
2:33 That's the script I'm running.
2:37 You could e-mail that to yourself.
2:38 You could potentially store it in a database.
2:42 There's a nice little challenge for you.
2:43 You figure out a way to store that data in a database.
2:46 Or you could just think of something else.
2:48 Anything you can think of, any other libraries that
2:50 you could use to do something interesting with that.
2:54 Come up with it, try your own feed and have fun with it
2:58 and go parse those feeds.