最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to interpret JavaScript with Python - Stack Overflow

programmeradmin2浏览0评论

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 some Java libraries, but I prefer Python.

Can someone give me a clue on this?

Best Regards,

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 some Java libraries, but I prefer Python.

Can someone give me a clue on this?

Best Regards,

Share Improve this question asked Mar 4, 2011 at 16:18 AndréAndré 25.6k44 gold badges124 silver badges181 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 5

You can check spidermonkey

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');
};

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/projects/remote-control/ (there are ways of doing that without needing a "physical" display for the browser, using VNC servers, for example)

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 )

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)

  1. 暂无评论