#100DaysOfCode in Python Transcripts
Chapter: Days 52-54: Parsing RSS feeds with Feedparser
Lecture: Concepts: what did we learn

Login or purchase this course to watch this video and the rest of the course contents.
0:00 And that's it, I told you it was simple. So Feedparser is awesome. A very, very simple and small lightweight thing to use
0:10 but really helps you out if you want to automate things like feeds. So, let's just recap quickly what we did without going into too much detail.
0:19 We import requests and this is for pulling down the XML feed. Okay. Specify the feed that we want to pull down, okay.
0:28 We actually get the feed using that URL and we store it in r. Okay. We then open a file, you can call this whatever you want,
0:39 and then we write the contents of that XML file, that feed, into the file that you specified there, okay. Simple. And now, onto the Feedparser stuff.
0:56 So obviously the first thing we do is import feedparser. Okay. Then we specify that actual file that we created in the last step.
1:07 Okay, remember we separated these two processes of pulling the file and then parsing it just in case you had
1:14 a scenario where, let's say you couldn't pull the file. Well, if you couldn't pull it, at least you have
1:20 an existing file and you can continue parsing that. The whole thing doesn't fall over, alright. Now we parse it using feedparser.parse and throw that
1:30 into the feed, all right. And then we have the little sanity check there to make sure the feed is okay to parse,
1:36 that it has that title tag that we want and that we did necessary again. You can wrap some sort of a try except or whatever
1:45 you know, error checking you want around that. Then for every entry within that feed we're going to take
1:53 the data stored against publish in the publish tag, in the title tag and the link tag and then we're going to print that in a nice little string
2:03 and that's it, okay. Now, very exciting. It's your turn. So for the next day I would like you, instead of printing out that data,
2:15 so in the previous step you saw we printed out the publish, the title and the link. Instead of printing it out,
2:23 why not do something interesting with it? What can you think that you might be able to do with it? So just some ideas, maybe you could e-mail that data
2:32 which is exactly what I'm doing with this steam stuff. That's the script I'm running. You could e-mail that to yourself.
2:39 You could potentially store it in a database. There's a nice little challenge for you. You figure out a way to store that data in a database.
2:47 Or you could just think of something else. Anything you can think of, any other libraries that you could use to do something interesting with that.
2:55 Come up with it, try your own feed and have fun with it and go parse those feeds.


Talk Python's Mastodon Michael Kennedy's Mastodon