view pyikriam/lazy/www/work/find.py @ 175:9f248c8460ce

Simplize xpath patterns. - Use 'descendant' aix name simplize patterns.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 02 Nov 2008 09:59:51 +0800
parents a4c364888197
children 60c4b4b78a01
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'
        parser = etree.HTMLParser(encoding=self.encoding)
        self.dom_tree = etree.parse(StringIO(self.working_prodcut.content), parser)
    
    def find(self, express , callback = None):
        xpath = self.dom_tree.xpath(express)
        
        if callback is None:
            ret = xpath
        else:
            ret = self.callback(xpath)
        return ret