Python 调用执行 JavaScript 代码。
PyJSCaller 是 Python 和 JavaScript 之间代理,是为了使 JavaScript 的代码调用更像是在使用 Python 一样。
一个简短的例子:
example.js
function add(a, b){ return a + b; }
>>> import jscaller >>> jscaller.eval("'Hello World!'.toUpperCase()") 'HELLO WORLD!'
>>> ctx = jscaller.compile('example.js', timeout=3) >>> ctx.call('add', 1, 1) 2
>>> with jscaller.session('example.js') as sess: ... add, math = sess.get('add', 'Math') ... res1 = add(2, 3) ... res2 = math.PI + math.E ... sess.call(res1, res2) ... >>> res1.get_value() 5 >>> res2.get_value() 5.859874482048838
>>> from jscaller.engine import PhantomJS >>> PhantomJS.test() 2.1.1 >>> PhantomJS.config(timeout=10) >>> jscaller.make(PhantomJS) >>> jscaller.eval('1+1') 2
$ pip install PyJSCaller
MIT license
- 简化使用流程。
- 支持 Python 3.x.x。
- 支持 Python 2.7.x。
- 完全重构。
- 上传代码。