comparison pyikriam/lazy/www/work/find.py @ 246:60c4b4b78a01

code clean
author "Hisn Yi, Chen <ossug.hychen@gmail.com>"
date Mon, 01 Dec 2008 00:25:07 +0800
parents a4c364888197
children
comparison
equal deleted inserted replaced
244:fd6c3660cd38 246:60c4b4b78a01
8 8
9 def __init__(self, working_product): 9 def __init__(self, working_product):
10 self.working_prodcut = working_product 10 self.working_prodcut = working_product
11 11
12 self.encoding = 'utf8' 12 self.encoding = 'utf8'
13 parser = etree.HTMLParser(encoding=self.encoding)
14 self.dom_tree = etree.parse(StringIO(self.working_prodcut.content), parser)
15 13
16 def find(self, express , callback = None): 14 def find(self, express , callback = None):
15
16 if self.dom_tree is None: self.set_dom_tree(self.working_prodcut.content)
17
17 xpath = self.dom_tree.xpath(express) 18 xpath = self.dom_tree.xpath(express)
18 19
19 if callback is None: 20 if callback: return self.callback(xpath)
20 ret = xpath 21 return xpath
21 else: 22
22 ret = self.callback(xpath) 23 def set_dom_tree(self, content):
23 return ret 24 stream = StringIO(content)
25
26 parser = etree.HTMLParser(encoding=self.encoding)
27 self.dom_tree = etree.parse(stream, parser)