25,344
社区成员
python代码
mport execjs import os os.environ["EXECJS_RUNTIME"] = "Node" # print(execjs.get().name) with open(r'cs1.js','r',encoding='utf-8') as f: js = f.read() print(js) ct = execjs.compile(js,cwd=r'C:\Program Files (x86)\nodejs\node_modules').call("signature") print(ct)
js代码
const jsdom = require("jsdom"); const { JSDOM } = jsdom; const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>'); window = global; var document = dom.window.document; function signature(){ return window }
报错
Traceback (most recent call last):
File "D:/scrapy_pro/DDD/get_sad.py", line 10, in <module>
ct = execjs.compile(js,cwd=r'C:\Program Files (x86)\nodejs\node_modules').call("signature")
File "D:\Python\lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
return self._call(name, *args)
File "D:\Python\lib\site-packages\execjs\_external_runtime.py", line 92, in _call
return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
File "D:\Python\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
return self.exec_(code)
File "D:\Python\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
return self._exec_(source)
File "D:\Python\lib\site-packages\execjs\_external_runtime.py", line 88, in _exec_
return self._extract_result(output)
File "D:\Python\lib\site-packages\execjs\_external_runtime.py", line 167, in _extract_result
raise ProgramError(value)
execjs._exceptions.ProgramError: SyntaxError: 语法错误
我在python程序里写js代码,报错语法错误是什么意思?环境都配好的呀
请问解决了吗,我好像跟你有一样的问题
程序说这个sign未定义,这个怎么补得(今日头条)
你的报错是语法错误。
我在本地运行你发的 js 没有这个问题
import execjs
import os
js = '''
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>');
window = global;
var document = dom.window.document;
function signature(){
return 1
}
'''
ct = execjs.compile(js,cwd=r'').call("signature")
print(ct)