How to load remote javascript into a SpiderMonkey context?

若如初见. 提交于 2019-12-24 08:25:37

问题


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:


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


来源:https://stackoverflow.com/questions/1931688/how-to-load-remote-javascript-into-a-spidermonkey-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!