sfdev

安装

pip install PyExecJS

方法

eval()
    输入参数:source(JS语句)、cwd(路径)
    返回值:result(语句执行结果)

compile()
    输入参数:source(JS语句)、cwd(路径)
    返回值:编译后的对象
call()
    输入参数:name(要调用的JS方法名称)、*args(方法所需要的参数,可多个)
    返回值:result(运行方法的返回结果)

模板

执行JS语句

import execjs
result=execjs.eval("1+1")
print(result)

调用JS方法

getUID = """
function getUID() {
	function a(a, b) {
		var e = (b || 2) - (1 + Math.floor(Math.log(a | 1) / Math.LN10 + 1E-15));
		return Array(e + 1).join("0") + a
	}
	var b = new Date;
	return "" + a(b.getHours()) + a(b.getMinutes()) + a(b.getSeconds()) + a(b.getMilliseconds(), 3) + a(Math.ceil(9999 * Math.random()), 4)
}
"""

import execjs
js=execjs.compile(getUID)
result=js.call(\'getUID\')
print(result)

分类:

技术点:

相关文章:

  • 2021-07-10
  • 2022-02-03
  • 2022-02-03
  • 2022-12-23
  • 2022-01-11
  • 2022-01-07
  • 2021-12-23
猜你喜欢
  • 2021-12-25
  • 2021-05-26
  • 2022-12-23
  • 2022-03-07
  • 2022-02-18
  • 2022-12-23
  • 2022-01-15
相关资源
相似解决方案