On Mar 23, 2014 11:31 AM, "tad na" <teddyb...@gmail.com> wrote: > OK . second problem :) > I can print the date. not sure how to do this one..
Why not? What happens when you try? > try: > from urllib2 import urlopen > except ImportError: > from urllib.request import urlopen > import urllib2 > from bs4 import BeautifulSoup > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > #print soup.find_all('item') > #print (soup) > data = soup.find_all("item") > > x=0 > for item in soup.find_all('item'): > title = item.find('title').text > link = item.find('link').text > date = item.find('pubDate') > # print date > print('+++++++++++++++++') > print data[x].title.text > print data[x].link.text > print data[x].guid.text > print data[x].pubDate > x = x + 1 data[x] should be the same object as item, no? If you want to keep track of the current iteration index, a cleaner way to do that is by using enumerate: for x, item in enumerate(soup.find_all('item')): As far as printing the pubDate goes, why not start by getting its text property as you do with the other tags? From there you can either print the string out directly or parse it into a datetime object.
-- https://mail.python.org/mailman/listinfo/python-list