我正在寻找一种从python函数调用js函数的方法。我来找您的原因是,我还需要我的js函数才能使用DOM,因此pyv8并不是解决方案。.你们有什么主意吗?可能吗

提前致谢。

最佳答案

根据https://stackoverflow.com/a/30537286/6353933

import js2py

js = """
function escramble_758(){
var a,b,c
a='+1 '
b='84-'
a+='425-'
b+='7450'
c='9'
document.write(a+c+b)
}
escramble_758()
""".replace("document.write", "return ")

result = js2py.eval_js(js)  # executing JavaScript and converting the result to python string

Js2Py的优点包括可移植性和与python的非常容易的集成(因为JavaScript基本上已被翻译成python)。

安装:
pip install js2py

09-27 04:16
查看更多