Resolver.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. re=self.mixbodyv(data,'zhibo','/html/head/script[1]/text()')
  12. return re
  13. def today(self,data):
  14. re=self.mixbodyv(data,'today','/html/head/script[2]/text()')
  15. return re
  16. def chain(self,data):
  17. re=self.mixbodyv(data,'chain','/html/head/script[2]/text()')
  18. return re
  19. def mixbodyv(self,data,fname,content_xpath):
  20. cpath=os.path.dirname(os.path.abspath(__file__))
  21. val=pycomm.readFile(cpath+'/tmpl/'+fname+'.tmpl')
  22. data=str(data.decode('utf-8'))
  23. doc = lxml.etree.HTML(data)
  24. # doc=lxml.etree.fromstring(data)
  25. ls=doc.xpath(content_xpath)
  26. text=ls[0]
  27. ftext=pycomm.parseTag(val,'CONTENT',text)
  28. ftext=str(ftext.encode('utf-8').decode('utf-8'))
  29. pycomm.saveFile(cpath+'/fcache/hg0088.'+fname+'.js',ftext)
  30. re=pycomm.exejs('node '+cpath+'/fcache/hg0088.'+fname+'.js')
  31. return re