4

Im using feed parser to obtain rss objects. When I run

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

live_leak.links[1]

I get list index out of range, mind you this was working earlier then all of a sudden this didn't work. I had this in my code and it took me hours to find because I didn't realize it was this that wasn't working. If no one knows I'll do a string replace as a hack but I rather do what was already working.

this also works

live_leak[0]

it returns

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

which is weird because the other one won't 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])
Community
  • 1
  • 1
losee
  • 2,190
  • 3
  • 29
  • 55

2 Answers2

0

You can index live_leak, but live_leak.links appears to be some other type of construct that returns the elements of live_leak. Try live_leak[1], perhaps?

Prune
  • 76,765
  • 14
  • 60
  • 81
0

One is looking for links under live_leak the other is just looking at live_leak itself.

for example: live_leak[1]

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

Nathan Kovac
  • 231
  • 2
  • 4