Mercurial > eagle-eye
view ikweb/tools/lazy/www/work/find.py @ 283:34fd5bcd4cf8
add some explan in README
author | billy3321@f3svr.f3.csu.edu.tw.f3.csu.edu.tw |
---|---|
date | Fri, 05 Dec 2008 15:39:49 +0800 |
parents | 7747bbe5b68e |
children |
line wrap: on
line source
from lxml import etree from cStringIO import StringIO class Finder: dom_tree = None xpath = None def __init__(self, working_product): self.working_prodcut = working_product self.encoding = 'utf8' def find(self, express , callback = None): if self.dom_tree is None: self.set_dom_tree(self.working_prodcut.content) xpath = self.dom_tree.xpath(express) if callback: return self.callback(xpath) return xpath def set_dom_tree(self, content): stream = StringIO(content) parser = etree.XMLParser(encoding=self.encoding) self.dom_tree = etree.parse(stream, parser)