Okay, this is starting to drive me a little bit nuts. I've tried several xml/xpath libraries for Python, and can't figure out a simple way to get a stinkin' "title" element.
The latest attempt looks like this (using Amara):
def view(req, url):
req.content_type = 'text/plain'
doc = amara.parse(urlopen(url))
for node in doc.xml_xpath('//title'):
req.write(str(node)+'\n')
But that prints out nothing. My XML looks like this: http://programanddesign.com/feed/atom/
If I try //*
instead of //title
it returns everything as expected. I know that the XML has title
s in there, so what's the problem? Is it the namespace or something? If so, how can I fix it?
Can't seem to get it working with no prefix, but this does work:
def view(req, url):
req.content_type = 'text/plain'
doc = amara.parse(url, prefixes={'atom': 'http://www.w3.org/2005/Atom'})
req.write(str(doc.xml_xpath('//atom:title')))