Runnning python script on HTML page - javascript

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)
<-------------/ <------------/

Related

How can I call a JavaScript library at only server side with Spring Boot?

I need to call JavaScript library on server side, which result will be returned to the user through Java.
This library uses many external JavaScript library, so it's not a single .js file.
Couple of options, but without more context, we can only guess.
Nashorn/GraalVM to execute Javascript from Java, but it depends on the library you're trying to invoke
Install Node.js on the server, write a Node.js script which uses that lib and invoke the script from Java. Depending on the complexity of the use case and how often you're trying to do this, maybe write a microservice in Node.js and call it from Java via REST.

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 to embed groovy script in html like in 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.

Call python from javascript [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Calling Python from JavaScript
I have a test.py and test.js.
I want to be able to run my test.py by opening test.js. I don't know how to create an api because it's not a web app, it's just 2 files sitting on my linux mint desktop.
I don't want to use npapi, because it's just a simple task, i don't want to use pyjamas because it's too hard to install the pyjamas desktop, so how to do it?
please note that i can use php, ajax, jquery instead of javascript, if it could be done with these languages. I am also able to use C++ or C instead of python. I just want to know a simple way to do it.
I know this can be done if i use java instead of python, but i want to know if i can do it with python, C or C++.
If you put your test.py file where ever you put your cgi files, (I think it's /usr/lib/cgi-bin by default for apache on ubuntu linux), you should be able to run the python file just by making a request to it's address.
If you just want to run the python file, and not use its output in the browser afterward,
you could probably get away with something like:
document.write('<img src="http://localhost/cgi-bin/test.py" />');
if you want to use the output in the browser, you will probably be best served by using jQuery or some other library to do an easy ajax call.
something like:
jQuery.get('/cgi-bin/test.py', function(data) {
//do stuff with the data
})
would probably do you just fine.
the second method would require that you also use apache, or equivalent, to serve the test.js file from localhost because jQuery ajax generally requires requests to go to the same domain that the script is running on.

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.

Categories