views:

174

answers:

1

I'm trying to parse an RSS/Podcast feed using Beautifulsoup and everything is working nicely except I can't seem to parse the 'pubDate' field.

data = urllib2.urlopen("http://www.democracynow.org/podcast.xml")
dom = BeautifulStoneSoup(data, fromEncoding='utf-8')
items = dom.findAll('item');

for item in items:
    title = item.find('title').string.strip()
    pubDate = item.find('pubDate').string.strip()

The title gets parsed fine but when it gets to pubDate, it says:

Traceback (most recent call last): File "", line 2, in AttributeError: 'NoneType' object has no attribute 'string'

However, when I download a copy of the XML file and rename 'pubDate' to something else, then parse it again, it seems to work. Is pubDate a reserved variable or something in Python?

Thanks,

g

A: 

It works with item.find('pubdate').string.strip(). Why don't you use feedparser ?

THC4k
thanks, changing to lowercase does the trick. Any idea why? I'll definitely check out feedparser. Seems much easier than beautifulsoup.
givp