views:

163

answers:

1

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?

A: 

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
mykhal