2

I'm trying to parse data from a RSS feed using feedparser module.

import feedparser

def main():
    try:
        rss = feedparser.parse('http://s.stooq.pl/rss/n.rss')
        print(rss.entries[0].title)

    except Exception as e:
        print(str(e))
main()

which gives me following output:

'ascii' codec can't encode character '\xf3' in position 55: ordinal not in range(128)

I tried to change the encoding to UTF-8, however it results in this:

b'Zostaniemy obs\xc5\x82u\xc5\xbceni w ka\xc5\xbcdym urz\xc4\x99dzie skarbowym' so this seems to be bytes literal.

What should I do with this string to display it properly ?

chilliq
  • 1,212
  • 3
  • 13
  • 32

1 Answers1

-2

Assuming property title is a string, you can try:

print(rss.entries[0].title.encode('utf-8'))
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304