开发者

pubDate RSS parsing weirdness with Beautifulsoup/Python

开发者 https://www.devze.com 2022-12-18 09:04 出处:网络
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.

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消