Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python feedparser not returning any entries

I've been cycling through RSS feeds over the past week using feedparser. When using it today, my entire program fails to function and I've noticed that the error seems to be at the start of the program, when I'm getting the length of the feed to cycle through.

So, for instance, if I was to cycle through the BBC feed, the program goes:

import feedparser

bbc = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml?edition=uk')

When running this, I get absolutely no output from the code that follows. Not even an error message. Before, I'd get all the headlines on the RSS feed. This has just suddenly stopped working today. It worked for the previous week. I've tried other RSS feeds and they turn up blank too.

Any ideas as to what could be wrong?

like image 271
Versace Avatar asked Jul 22 '26 03:07

Versace


1 Answers

You can use this code for sane error messages:

import feedparser

bbc = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml?edition=uk')
if bbc.status == 200:
    numberOfHeadlines = len(bbc['entries'])

    for i in range(0,numberOfHeadlines):
        print(bbc['entries'][i]['title'])
else:
    print("Some connection error", bbc.status)
like image 168
Bishakh Ghosh Avatar answered Jul 23 '26 16:07

Bishakh Ghosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!