Resolver.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import pycomm,os,lxml
  2. import mcollect
  3. class Resolver(object):
  4. def __init__(self):
  5. pass
  6. def zaopan(self,data):
  7. # print(mcollect.getMongo())
  8. re=self.mixbodyv(data,'zaopan','/html/head/script[2]/text()')
  9. return re
  10. def zhibo(self,data):
  11. print(data)
  12. re=self.mixbodyv(data,'zhibo','/html/head/script[1]/text()')
  13. return re
  14. def today(self,data):
  15. print(data)
  16. re=self.mixbodyv(data,'today','/html/head/script[2]/text()')
  17. print(re)
  18. return re
  19. def chain(self,data):
  20. re=self.mixbodyv(data,'chain','/html/head/script[2]/text()')
  21. return re
  22. def mixbodyv(self,data,fname,content_xpath):
  23. cpath=os.path.dirname(os.path.abspath(__file__))
  24. val=pycomm.readFile(cpath+'/tmpl/'+fname+'.tmpl')
  25. data=str(data.decode('utf-8'))
  26. doc = lxml.etree.HTML(data)
  27. # doc=lxml.etree.fromstring(data)
  28. ls=doc.xpath(content_xpath)
  29. text=ls[0]
  30. ftext=pycomm.parseTag(val,'CONTENT',text)
  31. ftext=str(ftext.encode('utf-8').decode('utf-8'))
  32. pycomm.saveFile(cpath+'/fcache/hg0088.'+fname+'.js',ftext)
  33. re=pycomm.exejs('node '+cpath+'/fcache/hg0088.'+fname+'.js')
  34. return re