python-execjs (call js)

A. Installation

pip3 install PyExecJS

电脑上要有nodejs环境

II. Use

A. Gets a string js

First save js As a local file or you can directly read the memory, you must make a string of shows js

Precautions: Do not appear in a string <script>js string tag

II. Conversion

js_obj = execjs.compile(上面转换的js字符串)

III. Js object method call

res = js_obj ( "method name", a parameter, two parameters .........)

III. When I use the experience

A js_obj, for example, need to complete a leave方法一(方法二的返回值(方法三的返回值))

Your code like this

js_obj = execjs.compile(js_str)

res_3 = js_obj("方法三")
res_2 = js_obj("方法二",res_3)
res_1 =js_obj("方法一",res_2)

#结果你会发现res_1并不是你想要的,而逻辑是毫无问题的

这可能是模块的bug导致的

解决方法

在js文件中定义一个三者封装后的函数

function func_1(res_2){......}
function func_2(res_3){......}
function func_3(){......}

//顶一个封装后方法
function my_func(){func_1(func_2(func_3()))}

Then call the method to our custom

Guess you like

Origin www.cnblogs.com/pythonywy/p/11927991.html