view pyikriam/lazy/www/work/find.py @ 308:f6f56a47f383

implemented is_tavern_enough
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 04 Jan 2009 23:49:41 +0800
parents 60c4b4b78a01
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.HTMLParser(encoding=self.encoding)
        self.dom_tree = etree.parse(stream, parser)