André
André

Reputation: 25554

Python and FeedParser question

I'm new to Python. I have this code using Feedparser:

import feedparser

d = feedparser.parse('http://pplware.sapo.pt/feed/')

i = range(10)

for i in range(10):
    updates = [{"url": d.entries[i].link, "msg": d.entries[i].summary + ", "}]

My question.

How can I add to the variable "updates" the 10 entries?

Best Regards,

Upvotes: 0

Views: 2426

Answers (2)

user2665694
user2665694

Reputation:

d = feedparser.parse('http://pplware.sapo.pt/feed/')
for item in d.entries[:10]:
    print item

Extracting information from 'item' and adding it to a list or dict is basic usage of Python lists and dicts (please read the tutorial in this case - we must not teach very basic usage of lists and dicts here).

Upvotes: 0

Sandro Munda
Sandro Munda

Reputation: 41030

import feedparser

d = feedparser.parse('http://pplware.sapo.pt/feed/')    
updates = []
for i in range(10):
    updates.append({"url": d.entries[i].link, "msg": d.entries[i].summary + ", "})

In your for loop, you append the dictionnary result to the updates list. 'updates' contains 10 elements after the for loop. One for each entry.

EDIT:

However, the code provided by RestRisiko is really more beautiful ;-)

Upvotes: 1

Related Questions