How to load remote javascript into a SpiderMonkey

2019-08-02 20:08发布

I have a server which will be serving up javascript files, I need to grab it and execute some of it's functions using SpiderMonkey in python. How can I do this?

1条回答
Evening l夕情丶
2楼-- · 2019-08-02 20:52

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
查看更多
登录 后发表回答