How to interpret JavaScript with Python

后端 未结 5 1914
滥情空心
滥情空心 2021-01-14 06:41

It is possible to run JavaScript with Python? There are any library that makes this possible?

I need to execute some JavaScript, I know that this is possible with so

相关标签:
5条回答
  • Does it need to be CPython ?

    And does the Javascript need a browser client environment ?

    If not, you can probably call Rhino from Jython.

    ( Note also that Jython release is only at 2.5.2 )

    0 讨论(0)
  • 2021-01-14 07:13

    You can check spidermonkey

    0 讨论(0)
  • 2021-01-14 07:14

    Yes you can execute JavaScript from Python. I find the easiest way is through Python's bindings to the webkit library - here is an example. In my experience selenium and spidermonkey are harder to get working.

    0 讨论(0)
  • 2021-01-14 07:16

    If you already use PyQt and QWebView in it, displaying custom html, the function evaluateJavaScript of QWebFrame may be useful for you:

    # Python
    def runJavaScriptText(self, jsText):
       jsText = 'hello()'  # just to fit javascript example
       self.webView.page().currentFrame().evaluateJavaScript(jsText)
    
    
    // Javascript
    function hello() {
        alert('hello');
    };
    
    0 讨论(0)
  • 2021-01-14 07:31

    Using spidermonkey would give you a tightier integration of your code, but as a workaround, you could make the javascript get run in a browser using Selenium remote-control:

    http://seleniumhq.org/projects/remote-control/ (there are ways of doing that without needing a "physical" display for the browser, using VNC servers, for example)

    0 讨论(0)
提交回复
热议问题