comparison pyikriam/buildings.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 8f699a9da6c0
children 3ba3edda6d1e
comparison
equal deleted inserted replaced
174:0cfc7a19a4d2 175:9f248c8460ce
18 return page 18 return page
19 pass 19 pass
20 20
21 class townhall(position): 21 class townhall(position):
22 xpath_patterns = { 22 xpath_patterns = {
23 'level': '/div/div/div[@class=\'buildingLevel\']/text()' 23 'level': 'div[@class=\'buildingLevel\']/text()'
24 } 24 }
25 25
26 def __init__(self, city_id, idx, baseurl): 26 def __init__(self, city_id, idx, baseurl):
27 super(townhall, self).__init__('townhall', city_id, idx, baseurl) 27 super(townhall, self).__init__('townhall', city_id, idx, baseurl)
28 pass 28 pass
29 29
30 def _sync(self, page): 30 def _sync(self, page):
31 parser = etree.HTMLParser(encoding='utf8') 31 parser = etree.HTMLParser(encoding='utf8')
32 page_dom = etree.parse(StringIO(page), parser) 32 page_dom = etree.parse(StringIO(page), parser)
33 xpath_building = '/html/body/div/div' 33 xpath_building = '/html/body/descendant::'
34 for name, ptn in self.xpath_patterns.items(): 34 for name, ptn in self.xpath_patterns.items():
35 path = xpath_building + ptn 35 path = xpath_building + ptn
36 value = page_dom.xpath(path)[0] 36 value = page_dom.xpath(path)[0]
37 setattr(self, name, value) 37 setattr(self, name, value)
38 pass 38 pass