例如:

#!/usr/bin/python
print "This is python."

print "<script type="text/javascript">
          var pass_to_python = new Number(7)
       </script>"

the_number = pass_to_python???

如何在python中获取pass_to_python?

最佳答案

使用pyv8,您可以在Python中执行javascript。

import PyV8

class Global(PyV8.JSClass):
    pass

with PyV8.JSContext(Global()) as ctxt:
    the_number = ctxt.eval("var pass_to_python = new Number(7)")

http://code.google.com/p/pyv8/

07-28 07:03