import execjs with open('xxx.js','rt',encoding='utf-8') as f: js = execjs.compile(f.read(),cwd='../../node_modules') # cwd= 为加入dom和window环境供js代码运行, cnpm install jsdom ''' const jsdom = require("jsdom"); const { JSDOM } = jsdom; const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`); window = dom.window; document = window.document; XMLHttpRequest = window.XMLHttpRequest; ''' data = js.call(function,参数)