开发者

How to load remote javascript into a SpiderMonkey context?

I have a server which will be serving up javascript files, I need to grab it and exec开发者_如何学Cute some of it's functions using SpiderMonkey in python. How can I do this?


hope the following example helps:

>>> import urllib2
>>> import spidermonkey
>>> js = spidermonkey.Runtime()
>>> js_ctx = js.new_context()
>>> script = urllib2.urlopen('http://etherhack.co.uk/hashing/whirlpool/js/whirlpool.js').read()
>>> js_ctx.eval_script(script)
>>> js_ctx.eval_script('var s = "abc"')
>>> js_ctx.eval_script('print(HexWhirlpool(s))')
4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜