PubDate RSS parsing weirdness with Beautifulsoup / Python

I am trying to parse an RSS / Podcast feed using Beautifulsoup and everything works fine, but I cannot 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 header gets parsed, but when it gets into pubDate, it says:

Traceback (last last call): File "", line 2, in AttributeError: object "NoneType" does not have the 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?

Thank,

g

+3
source share
1 answer

item.find('pubdate').string.strip(). feedparser?

+3

Source: https://habr.com/ru/post/1730679/


All Articles