首页 新闻 会员 周边 捐助

如何使用python的execjs模块运行javascript的自调用函数

0
悬赏园豆:10 [已解决问题] 解决于 2020-07-29 17:56
(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p})('q g=g=\'["n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/m.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/p.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/r.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/s.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/k.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/h.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/i.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/j.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/l.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/o.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/D.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/A.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/B.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/C.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/E.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/z.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/y.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/u-t.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/v.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/w.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/x.5"]\';',41,41,'E5|8F|90|88|B3|jpg|A5|8B|E6|9D|8C|E8|AF|E7|AC02|AC|pages|43|44|45|42|46|38||47|39|var|40|41|056|055|057|058|059|054|053|049|050|051|048|052'.split('|'),0,{})

就是这串代码,如何使用execjs去运行?求大佬给出详细代码

JKding233的主页 JKding233 | 初学一级 | 园豆:186
提问于:2020-07-29 08:46
< >
分享
最佳答案
0

你说一下你运行这段js你入参是什么,调用js中哪个方法

js_obj = execjs.compile('你上述的js 代码')
res = execjs.call('方法名',入参)
#这个模块很久没跟新了不建议使用
#推荐直接nodejs运行js
收获园豆:10
小小咸鱼YwY | 老鸟四级 |园豆:3312 | 2020-07-29 17:01

你好,我知道可以直接使用nodejs运行,但是我后续的处理需要在py中,但是这个是js的自调用函数,所以不知道怎么写
aeBHD1.png

JKding233 | 园豆:186 (初学一级) | 2020-07-29 17:11

@JKding233: 动动你的小脑瓜子不就能知道了

//js字符串
function test(){
把你那一大串丢进去
把结果return一下,太多了我也不想仔细看
}
#python脚本
js_obj = execjs.compile('你上述的js 代码')
res = execjs.call('test')

小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2020-07-29 17:18

@JKding233: 至于node怎么调用我最近博客有发过你可以看看很简单,https://www.cnblogs.com/pythonywy/p/13221152.html,没什么时间总结应该不好找链接弄出来了自己看看

小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2020-07-29 17:20

@JKding233:
你复制过去吧

//return 换成console
(function (p, a, c, k, e, d) {
    e = function (c) {
        return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
    };
    if (!''.replace(/^/, String)) {
        while (c--) {
            d[e(c)] = k[c] || e(c)
        }
        k = [function (e) {
            return d[e]
        }];
        e = function () {
            return '\\w+'
        };
        c = 1
    }
    ;
    while (c--) {
        if (k[c]) {
            p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c])
        }
    }
    console.log(p)
})('q g=g=\'["n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/m.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/p.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/r.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/s.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/k.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/h.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/i.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/j.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/l.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/o.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/D.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/A.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/B.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/C.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/E.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/z.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/y.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/u-t.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/v.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/w.5","n\\/%0%6%4%0%1%7%8%3%2%0%1%a\\/%d%f%e%b%c%9\\/x.5"]\';', 41, 41, 'E5|8F|90|88|B3|jpg|A5|8B|E6|9D|8C|E8|AF|E7|AC02|AC|pages|43|44|45|42|46|38||47|39|var|40|41|056|055|057|058|059|054|053|049|050|051|048|052'.split('|'), 0, {})
import os

a = os.popen('node aa.js').read()
print(a)
小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2020-07-29 17:32

@小小咸鱼YwY: 感谢

JKding233 | 园豆:186 (初学一级) | 2020-07-29 17:55

@JKding233: 哈哈,爬虫很活的没那么死板

小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2020-07-29 20:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册