0
点赞
收藏
分享

微信扫一扫

python执行xxx.js文件方式

小铺有酒一两不够 2022-04-22 阅读 50
python

1.pip install pyexecjs
2.js文件如下


```javascript
function encode2(phone) {
   return 'hahaha'+phone
  }
3.调用

```python
import os
import execjs


def testPy(phone: str):
    print('当前目录是:', os.getcwd())
    #调用js步骤1
    rFile = open(r"D:\pythonprojects\python-auto-test\anshiyatai\fzx_khd\js_test\jsencrypt.min.js", 'r',
                 encoding='UTF-8')
    testResult = execjs.compile(rFile.read()).call('encode2', phone)

    return testResult


def get_jiami(phone: str):
    # 运行环境:JScript,Node,PhantomJS
    # 调用js步骤2
    os.environ["EXECJS_RUNTIME"] = "Node"
    return testPy(phone)


if __name__ == '__main__':
    print(get_jiami('111111'))


4.结果



举报

相关推荐

0 条评论