[关闭]
@bergus 2015-12-12T02:49:34.000000Z 字数 1030 阅读 1916

Ubuntu下安装PyV8

python pyv8


折腾一下午终于弄好PyV8引擎,解析JS方便多了.
关键: PyV8依赖于Boost,所以安装前先确定你的Linux有没有Boost(就因为这个折腾一下午,官方首页也没说,找了好久)

  1. Ubuntu下安装
  2. sudo apt-get install libboost-all-dev
  3. sudo apt-get install aptitude
  4. 接着安装PyV8
  5. pip安装
  6. $sudo pip install -v pyv8
  7. 或:
  8. sudo apt-get install scons libboost-python-dev
  9. svn checkout http://v8.googlecode.com/svn/trunk/ v8
  10. svn checkout http://pyv8.googlecode.com/svn/trunk/ pyv8
  11. cd v8
  12. export V8_HOME=`/home/buffer/v8`
  13. cd ../pyv8
  14. sudo python setup.py build
  15. sudo python setup.py install

接着就可以快乐的使用PyV8了....附使用代码

  1. import PyV8
  2. class v8Doc(PyV8.JSClass):
  3. def write(self, s):
  4. print s.decode('utf-8')
  5. class Global(PyV8.JSClass):
  6. def __init__(self):
  7. self.document = v8Doc()
  8. glob = Global()
  9. ctxt = PyV8.JSContext(glob)
  10. ctxt.enter()
  11. ctxt.eval("var ant=8257+4341;var calf=5749+403^ant;var goat=1986+4175^calf;var fish=6422+7944^goat;var worm=7920+3648^fish;")
  12. ctxt.eval("document.write(((10502^calf)+24).toString());")
  13. jss = "document.write((10502^calf)+24);"
  14. jss = "var thisvalue = " + jss.strip().replace("document.write(","").replace(");",";")
  15. print jss
  16. ctxt.eval(jss)
  17. vars = ctxt.locals.thisvalue
  18. print "vars = " + str(vars)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注