diff 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
line wrap: on
line diff
--- a/pyikriam/lazy/www/work/find.py	Fri Nov 14 02:05:48 2008 +0800
+++ b/pyikriam/lazy/www/work/find.py	Mon Dec 01 00:25:07 2008 +0800
@@ -10,14 +10,18 @@
         self.working_prodcut = working_product
 
         self.encoding = 'utf8'
-        parser = etree.HTMLParser(encoding=self.encoding)
-        self.dom_tree = etree.parse(StringIO(self.working_prodcut.content), parser)
     
     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 is None:
-            ret = xpath
-        else:
-            ret = self.callback(xpath)
-        return ret
+        if callback:    return self.callback(xpath)
+        return xpath
+
+    def set_dom_tree(self, content):
+        stream = StringIO(content)
+
+        parser = etree.HTMLParser(encoding=self.encoding)
+        self.dom_tree = etree.parse(stream, parser)
\ No newline at end of file