I get an index index error out of range for an index that exists

Im uses a parser to get rss objects. When i started

live_leak.links

I get

[{'type': 'text/html', 'rel': 'alternate', 'href': 
'http://www.liveleak.com/view?i=abf_1476121939'}, 

{'type': 'application/x-shockwave-flash', 'rel': 'enclosure', 'href':
 'http://www.liveleak.com/e/abf_1476121939'}]

But when I try this one

live_leak.links[1]

I get an index index out of range, remember that you worked before, and suddenly it didn’t work. I had this in my code, and it took me several hours to find, because I did not understand that this was not working. If no one knows that I will do the string replacement as a hack, but I will rather do what already works.

it also works

live_leak[0]

he returns

[{'type': 'text/html', 'rel': 'alternate', 'href': 
'http://www.liveleak.com/view?i=abf_1476121939'}]

which is strange because the other will not work

EDIT

def pan_task():
        url = 'http://www.liveleak.com/rss?featured=1'
        name = 'live leak'
        live_leaks = [i for i in feedparser.parse(url).entries]
        the_count = len(live_leaks)
        ky = feedparser.parse(url).keys()
        oky = [i.keys() for i in feedparser.parse(url).entries][:12] # shows what I can pull

        try:
            live_entries = [{
                             'html': live_leak.links,
                             'href': live_leak.links[0]['href'],
                             'src': live_leak.media_thumbnail[0]['url'],
                             'text': live_leak.title,
                             'comments': live_leak.description,
                             'url': live_leak.links[0]['href'],
                             'embed': live_leak.links[1]['href'],
                             'text': live_leak.title,
                             'comments': live_leak.description,
                             'name': name,
                             'url': live_leak.link, # this is the link to the source
                             'author': None,
                             'video': False
                             } for live_leak in live_leaks]
        except IndexError:
            print('error check logs')
            live_entries = []

        # for count, elem in enumerate(live_entries):
        #     the_html = requests.get(live_entries[count]['url']) # a specific text

        return print(live_entries[0])
+4
source share
2 answers

live_leak, live_leak.links , live_leak. live_leak [1], ?

0

live_leak, live_leak.

: live_leak [1]

: [{'type': 'application/x-shockwave-flash', 'rel': 'enclosure', 'href':  'http://www.liveleak.com/e/abf_1476121939'}]

0

Source: https://habr.com/ru/post/1657327/


All Articles