I know that Python can be a server-side language but is there a way to make python act like a client side language (like javascript) i just want to try it out if its possible thank you
You can compile your python to javascript with Pyjs.
Note that if you use Skulpt, Skulpt will NOT let you create full websites or actual javascript code that can run inside browsers. For this, you must use Pyjs. Pyjs essentially transforms your Python code into actual Javascript, so you can run the resulting Javascript in any browser, or host it as a website.
Try http://www.skulpt.org/ it is an entirely in the browser implementation of Python.
Or you could try this: http://pypyjs.org/.
It uses the PyPy python interpreter, compiled for the web via emscripten, with a custom JIT backend that emits asm.js code at runtime.
I think you want online python compiler to test the code/snippet that run on browser, try repl.it
I am guessing you know python and want everything to be in python. Well dont do it. Seriously dont even use that skulpt solution that was posted. Not because it wouldnt work. Its more because browsers only understand Javascript as a front end program. No other language is understood. If you understand python, using javascript should be a piece of cake and you might as well start that. If you really want to use python, atleast transpile into javascript using http://pyjs.org/
Pyodide gives you a full, standard Python interpreter that runs
entirely in the browser, with full access to the browser’s Web APIs.
article
https://hacks.mozilla.org/2019/04/pyodide-bringing-the-scientific-python-stack-to-the-browser/
download
https://github.com/iodide-project/pyodide
Related
If I can build a server with node.js do I need tomcat?
Excuse me, I'm a pretty new to it and I'd like to understand this base concepts. Thank you so much!
No, you do not need Tomcat if you are using Node. You could run one or the other, or both at the same time as long as they are not trying to listen on the same port. Here's why.
Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.
Basically, this means that Tomcat is designed specifically to be a web server.
Node is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Basically, this means that Node can take JavaScript code, optimize it, and give the code access to things that aren't normally exposed to JavaScript code that is run in a web browser, like direct access to the file system. JavaScript is similar to Python, lacking strict data typing, but unlike Python which is an interpreted language, Node reads JavaScript and turns it into machine code which does not require it to be interpreted before it is executed (so it can be much faster).
Node happens to be good for developing servers especially when using frameworks like Express, sort of like Rails for Ruby, or Flask for Python, but you can write anything you want, it doesn't have to be a server.
The title says it all.
I spent a lot of time designing a sketch in Processing using the Python language.
Now, I would like to put the sketch on a webpage.
Of course, I could just translate the sketch from python language to javascript and use a javascript library for processing.
However, this would be a very lengthy process. As such, do you know if there is a way to integrate a python sketch in the website? If yes, how to do that?
Thank you in advance!
At the moment there is no straightforward way to do this. But some workarounds can be found. For example, since Processing's python mode is using Jython language (Python on JVM) you can do the following:
Compile the Jython code to Java bytecode
Decompile Java bytecode to real Java code
Use processing.js to make the sketch run in a webpage
Of course, there are chances that the generated Java code will not be 100% Processing code, thus will not be converted to Javascript by the processing.js library.
This is part of a project I am working on for work.
I want to automate a Sharepoint site, specifically to pull data out of a database that I and my coworkers only have front-end access to.
I FINALLY managed to get mechanize (in python) to accomplish this using Python-NTLM, and by patching part of it's source code to fix a reoccurring error.
Now, I am at what I would hope is my final roadblock: Part of the form I need to submit seems to be output of a JavaScript function :| and lo and behold... Mechanize does not support javascript. I don't want to emulate the javascript functionality myself in python because I would ideally like a reusable solution...
So, does anyone know how I could evaluate the javascript on the local html I download from sharepoint? I just want to run the javascript somehow (to complete the loading of the page), but without a browser.
I have already looked into selenium, but it's pretty slow for the amount of work I need to get done... I am currently looking into PyV8 to try and evaluate the javascript myself... but surely there must be an app or library (or anything) that can do this??
Well, in the end I came down to the following possible solutions:
Run Chrome headless and collect the html output (thanks to koenp for the link!)
Run PhantomJS, a headless browser with a javascript api
Run HTMLUnit; same thing but for Java
Use Ghost.py, a python-based headless browser (that I haven't seen suggested anyyyywhere for some reason!)
Write a DOM-based javascript interpreter based on Pyv8 (Google v8 javascript engine) and add this to my current "half-solution" with mechanize.
For now, I have decided to use either use Ghost.py or my own modification of the PySide/PyQT Webkit (how ghost works) to evaluate the javascript, as apparently they can run quite fast if you optimize them to not download images and disable the GUI.
Hopefully others will find this list useful!
Well you will need something that both understands the DOM and understand Javascript, so that comes down to a headless browser of some sort. Maybe you can take a look at the selenium webdriver, but I guess you already did that. I don't hink there is an easy way of doing this without running the stuff in an actually browser engine.
I'm trying to execute JavaScript in a C# program, and I'm trying to determine:
Would it be better to create a state machine for JavaScript, or should it be compiled into MSIL before executing it?
I'm really looking for techniques rather than solutions. Some attempt to compile the JavaScript, there by treating it as a programming language, others use a state machine and treat it as it was meant to be : a scripting language.
Any documentation on the methods used for executing is welcome also.
The easiest way to run JS in a C# program is to use one of the existing .Net JS runtimes: IronJS, Jurassic, and Jint. If you're interested in adding another .Net-based interpreter to the mix, examining their code is where I'd start; If you're embedding JS in your program then using a preexisting one is probably the way to go.
You haven't explained your scenario - how much javascript, how often does it get executed, how often does it change, how closely integrated it needs to be with the C# logic, and so on.
If it rarely changes, then it may be smart to compile it into MSIL via one of the alternatives.
If it changes "constantly" then it might make sense to stand up a JS compiler and send it JS as necessary. It's something like a REPL for Javascript, that you'd use programmatically. Node.js offers a server that can do REPL operations; it could listen on a port, you send it JS to evaluate, and it sends back the result. There's a free w3sockets component that could be used from cscript.exe to do something similar: for example you could build a "host" Javascript shell that listens on a socket, executes the js it receives, then sends back the result.
If it needs to be closely integrated with the C# code, then you'll have to be smarter about this. One way to do it might be to host the JS in a Windows Script Component and have the C# code invoke the JS logic via COM. You can also do the converse - have the JS host invoke the C# layer via COM to gather input and deliver results.
EDIT
A better way is to use the IActiveScript stuff - this is the official way Microsoft makes it possible to host scripting within an application. There's a winforms example published here.
OR better, see parse and execute JS by C#
Using that code I put together a demonstration of how to parse and invoke Javascript from a .NET app, using IActiveScript.
You can download a VS2010 project for this app here.
I would like to setup a simple web browser that download a html page , parse it, generate a dom and execute the javascript code. I would like to know if there is a simple project(so not firefox which is good but too big to just understand this piece of logic) showing if it is the right way to handle this or someone to explain me if i am missing something. No particular language( but preferably be python, c#/c++/c ). I am stuck now at integrating the javascript engine, i don't know what to do.
Thx
I don't think its easy to pull off a javascript engine on your own. You could however use an open source engine (like WebKit's JS engine for example) and integrate it in your project.
More Infos:
http://www.webkit.org
google chrome is open source too with a neat javascript engine v8.
http://code.google.com/chromium/
http://code.google.com/p/v8/
another way could be nodejs. it's server side javascript using the v8 engine. so there is no rendering, just pure javascript. maybe thats enough if you do not need the rendering.
http://nodejs.org/
You might want to use the WebBrowser class from .NET for that purpose.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx