how to embed groovy script in html like in javascript? - javascript

is it possible to embed groovy script in html like in javascript?
I want to have an onclick button event that use groovy script instead of javascript
Thanks

You can't
You could use AJAX to call the webserver which would run a groovy script, but you can't run groovy in the browser like JavaScript.
(For completeness in this answer, I guess you could roll an applet with groovy support, and then use the applet to execute bits of groovy, but I would just write the script in javascript and miss out this sort of Rube-goldberg machination)

It's a rather old project, and I'm not sure quite how far it actually went, but Andres Almiray has done some work on getting the ability to run Groovy in the browser, via Grapplet.
I haven't used it myself, but it looks promising.

Related

Runnning python script on HTML page

I would like to basically call a python script from HTML, after the script is called and it finished running, I would like to execute a javascript file(wich I know how to do.) Now my question is: Can I do this with just pure HTML and javascript or do I need to get a library for python? If I dont need a library, how would I go about doing this?
You can use Two Python libraries.
Django
Flask
I recommend Django. Django is easy and fast to make.
the Flask is more complex but you can make more detail functions.
Can I do this with just pure HTML and javascript?
You might want to execute python on the browser, then look at something like this http://www.skulpt.org/, but the most common use case is that no, you need to execute javascript on the browser client-side and python on server-side
So no, you need something that executes python in a web server (apache/nginx) context, like
gunicorn (standalone/wsgi)
uwsgi (standalone/wsgi)
mod_python (apache module)
Then you would execute like this for example
browser ---http---> server(nginx) ---wsgi---> python_server(uwsgi)+library(Django)
<-------------/ <------------/

Can groovy run javascript?

I'm a newbie in groovy and javascript. I'm trying to make a groovy script that runs a javascript in it.
Is it possible for groovy to run a javascript on its class? If it is possible, then how can a groovy script run a javascript?
Some sample syntax will be a big help!
It depends on the javascript code you want to run.
If your javascript only involves some basic operations etc, you could use ScriptEngieManager, http://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngineManager.html
Just include the library at the beginning of your groovy script:
import javax.script.*
If your javascript code involves DOM manipulation and/or stuff that has to do with a browser to function properly, you'll need a java-based browser like htmlUnit: http://htmlunit.sourceforge.net/

How can I convert web page with javascript to plain html?

I want to convert some web pages with javascript to plain html, and I found there several ways(pls tell me if I'm wrong):
Use Jython, an example: http://blog.databigbang.com/web-scraping-ajax-and-javascript-sites/
Use Java together with htmlunit
Use a proxy, an example: http://grep.codeconsult.ch/2007/02/24/crowbar-scrape-javascript-generated-pages-via-gecko-and-rest/
Use python together with qt or PyV8
Because I want to make a tiny tool to meet my request, and I thought it somewhat complicated to install V8 and qt, although python is my first choice.
So I tried to make a proxy with gecko, but it seems need a DISPLAY which I can not afford in a remote Linux server.
Now I am trying to use jython, but it seems there is no simple way to just convert a whole page to plain html.
Actually, I want to ask is there a way to convert a web page contains javascript to plain html, just like the brower does. Can node.js do this job?
I've recently built a server on top of PhantomJS that does this. I highly recommend this route.
http://phantomjs.org/
Basically, you write a quick script that has PhantomJS run the page, and configure a trigger method that lets you know the page is finished and sends the data off. My version used the built-in HTTP server, so PhantomJS easily served up the results on its own. This takes about 15 lines of code to do. (Sorry, can't paste it here... wrote it on work time. But, check out the example on their home page. It's almost complete!)

How can I execute a Python script from Javascript?

I have written a module in python which performs some function.
I then created a Google Chrome extension which makes use of JSON and javascript.
Now when I click on the extension I want it to execute the python program which is stored on my hard disk and display the output on the browser again.
Is there a way in which I can do this??
Repeated :
Calling Python from JavaScript
Here you have some answers, Pyjamas is probably the best option in your case
Probably a late reply but a possible solution is to make your python script act as a server and let the browser plugin interact with it.
forgive me if i'm incorrect on infinite proportions.
I believe that JavaScript is executed in a sandboxed/ isolated environment. Therefore you cannot invoke a python interpreter* or any other executable residing on the system.
*unless the interpreter itself were written in javascript.

Can any of Ruby's HTML Parsers do JavaScript to see the resulting DOM?

When trying Hpricot and Nokogiri, the HTML can be fetched and parsed, but can they also execute the Javascript as well so that the content shows on the page? (shows up in the the DOM). That's because some page won't show the info unless the JavaScript initialization code has run.
Not that I know of. You might want to look into using something like Watir and use a real browser.
Take a look at envjs and johnson gems.
Have a look at Capybara. I haven't used it myself but I read about it the other day and it seems like it can execute javascript without using a browser.

Categories