help with for loop----python 2.7.2

teddybubu at gmail.com teddybubu at gmail.com
Sat Mar 22 07:21:30 EDT 2014


I am trying to get all the element data from the rss below.
The only thing I am pulling is the first element.
I don't understand why the for loop does not go through the entire rss.
Here is my code....


try:
    from urllib2 import urlopen
except ImportError:
    from urllib.request import urlopen 

from bs4 import BeautifulSoup 

soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss'))
#print soup.find_all('item')
#print (soup)

for item in soup.find_all('item'):
#for item in soup:    
    title = soup.find('title').text    
    link = soup.find('link').text
    item = soup.find('item').text
    print item
    print title
    print link



More information about the Python-list mailing list