View Single Post
Old 12-14-2015, 09:42 AM   #5
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Alright, but you still need to parse the resulting XML string to extract the value.

Anyway, just my two cents.

I am currently using:
Code:
    def get_meta(self, meta, default=""):
        value = default
        try:
            import lxml.etree as etree
            opf = self.bk.get_opf().encode("utf-8")
            root = etree.fromstring(opf)
            query = "//dc:%s" % (meta)
            namespaces = {"dc": "http://purl.org/dc/elements/1.1/"}
            dc_elem = root.xpath(query, namespaces=namespaces)
            if len(dc_elem) > 0:
                value = dc_elem[0].text
        except:
            pass
        return value
AlPe is offline   Reply With Quote