Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a Javascript function from Python?

I am working on a web-scraping project. One of the websites I am working with has the data coming from Javascript.

There was a suggestion on one of my earlier questions that I can directly call the Javascript from Python, but I'm not sure how to accomplish this.

For example: If a JavaScript function is defined as: add_2(var,var2)

How would I call that JavaScript function from Python?

like image 271
Kiran Avatar asked Nov 27 '11 10:11

Kiran


People also ask

How do you call a JavaScript code from Python?

Use ajax to Call Python From JavaScript. AJAX stands for Asynchronous JavaScript and XML. It utilizes the XMLHttpRequest object to communicate with servers. It can send and receive information in numerous formats, including HTML, XML, JSON, and text files.

Can you use JavaScript and Python together?

Answer: No, Python cannot replace Javascript. In fact, the two languages complement each other. Javascript is used as a client-side scripting language, whereas Python is mostly used as a server-side scripting language.

How do you call a node JS function in Python?

To call a Python function from Node. js, we can call the spawn method. const { spawn } = require("child_process"); const pythonProcess = spawn('python', ["path/to/script.py", arg1, arg2]); to call the spawn method available in the child_process module.


1 Answers

Find a JavaScript interpreter that has Python bindings. (Try Rhino? V8? SeaMonkey?). When you have found one, it should come with examples of how to use it from python.

Python itself, however, does not include a JavaScript interpreter.

like image 143
Has QUIT--Anony-Mousse Avatar answered Nov 04 '22 14:11

Has QUIT--Anony-Mousse