4

How can I retrieve the openSearch:totalResults attribute using feedparser?

I have a blogger API result which looks a bit like this (I have cut out some stuff to make it compact here)

 <feed xmlns='http://www.w3.org/2005/Atom'
  xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
  xmlns:gd='http://schemas.google.com/g/2005'
  gd:etag='W/"CUYMQ348fyp7ImA9WB9UFkU."'>
 <id>tag:blogger.com,1999:blog-blogID.postpostID..comments</id>
 <updated>2007-12-14T17:46:22.077-08:00</updated>
 <title>Comments on Lizzy's Diary: Quite disagreeable</title>  
 <generator version='7.00'
   uri='http://www.blogger.com'>Blogger</generator>
 <openSearch:totalResults>1</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>

Currently, I do something like

req = urllib.urlopen(url)
urlContent = req.read()            
feed = feedparser.parse(urlContent)
print feed.feed['openSearch_totalResults']

I get an error with the above code that the attribute does not exist. I have confirmed that the feed parser has the namespace by running

print feed['namespaces']

which gives me

{'': u'http://www.w3.org/2005/Atom', u'gd': u'http://schemas.google.com/g/2005', u'thr': u'http://purl.org/syndication/thread/1.0', u'openSearch': u'http://a9.com/-/spec/opensearchrss/1.0/'}
N.P
  • 245
  • 1
  • 12

1 Answers1

0

There is a problem with the capitalization: it should be opensearch_totalresults instead of openSearch_totalResults. Thus, the correct line would be:

print feed.feed['opensearch_totalresults']
user936580
  • 1,223
  • 1
  • 12
  • 19