如何用spidermonkey在python里调用javascript代码
1个回答
展开全部
由于PyQt的安装比较麻烦,尝试了几次都没有成功,便决定用spidermonkey,但若直接从官网下载和安装,由于涉及到js引擎等的安装,比较麻烦,经过试验验证,如下方法可以快速达到目的:
1.spidermonkey下载及安装
1)下载 svn checkout http://python-spidermonkey.googlecode.com/svn/trunk spidermonkey
2)编译安装
python setup install
3)如果编译时出现
spidermonkey.pyx:82:3: Syntax error in simple statement list 这样错误:则修改spidermonkey.pyx:注释如下代码
#IF UNAME_MACHINE == "x86_64":
#ctypedef long jsval
#ELSE:
#ctypedef int jsval
增加:
ctypedef long jsval
4)如果编译时出现
spidermonkey.c:1323: error: invalid lvalue in assignment,则修改spidermonkey.c程序:
注释:
/*((PyObject *)((struct __pyx_obj_12spidermonkey_Context *)__pyx_v_self)->rt) = ((PyObject *)__pyx_v_rt);*/
新增:
((PyObject *)((struct __pyx_obj_12spidermonkey_Context *)__pyx_v_self)->rt) = (PyObject *)__pyx_v_rt;
如果还是报以上错误,则新增的这条语句也去掉
2.如何在python中调用js:
ECASE)
con=regex.search(content)
rt = Runtime()
cx = rt.new_context()
jsCode= "var acc = g1656.substr(3,3) + da2ef.substr(5,5) + 'abc';" #注意:以分号结束
cx.eval_script(jsCode)
acc = cx.get_global('acc')
1.spidermonkey下载及安装
1)下载 svn checkout http://python-spidermonkey.googlecode.com/svn/trunk spidermonkey
2)编译安装
python setup install
3)如果编译时出现
spidermonkey.pyx:82:3: Syntax error in simple statement list 这样错误:则修改spidermonkey.pyx:注释如下代码
#IF UNAME_MACHINE == "x86_64":
#ctypedef long jsval
#ELSE:
#ctypedef int jsval
增加:
ctypedef long jsval
4)如果编译时出现
spidermonkey.c:1323: error: invalid lvalue in assignment,则修改spidermonkey.c程序:
注释:
/*((PyObject *)((struct __pyx_obj_12spidermonkey_Context *)__pyx_v_self)->rt) = ((PyObject *)__pyx_v_rt);*/
新增:
((PyObject *)((struct __pyx_obj_12spidermonkey_Context *)__pyx_v_self)->rt) = (PyObject *)__pyx_v_rt;
如果还是报以上错误,则新增的这条语句也去掉
2.如何在python中调用js:
ECASE)
con=regex.search(content)
rt = Runtime()
cx = rt.new_context()
jsCode= "var acc = g1656.substr(3,3) + da2ef.substr(5,5) + 'abc';" #注意:以分号结束
cx.eval_script(jsCode)
acc = cx.get_global('acc')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询