@bergus
2015-12-12T02:49:34.000000Z
字数 1030
阅读 2128
python pyv8
折腾一下午终于弄好PyV8引擎,解析JS方便多了.
关键: PyV8依赖于Boost,所以安装前先确定你的Linux有没有Boost(就因为这个折腾一下午,官方首页也没说,找了好久)
Ubuntu下安装sudo apt-get install libboost-all-devsudo apt-get install aptitude接着安装PyV8用pip安装$sudo pip install -v pyv8或:sudo apt-get install scons libboost-python-devsvn checkout http://v8.googlecode.com/svn/trunk/ v8svn checkout http://pyv8.googlecode.com/svn/trunk/ pyv8cd v8export V8_HOME=`/home/buffer/v8`cd ../pyv8sudo python setup.py buildsudo python setup.py install
接着就可以快乐的使用PyV8了....附使用代码
import PyV8class v8Doc(PyV8.JSClass):def write(self, s):print s.decode('utf-8')class Global(PyV8.JSClass):def __init__(self):self.document = v8Doc()glob = Global()ctxt = PyV8.JSContext(glob)ctxt.enter()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;")ctxt.eval("document.write(((10502^calf)+24).toString());")jss = "document.write((10502^calf)+24);"jss = "var thisvalue = " + jss.strip().replace("document.write(","").replace(");",";")print jssctxt.eval(jss)vars = ctxt.locals.thisvalueprint "vars = " + str(vars)
