Home > Mobile >  how to run python script in javascript
how to run python script in javascript

Time:05-09

how I use python scrip in JavaScript ?

I want to make a live web scraper. And Python is the best for web scraping. But I'm trying to run Python code on the front-end. So that the performance of my application is good.

CodePudding user response:

I'm not a Python developer, so maybe python is better for web scraping... however web craping is done on the back-end, and there for you would not need python on the front-end (it is an option, but it wont make a difference).

In fact, JavaScript would perform better than python on the front end because it is 1 - made for the browser without the need for plug-ins, and 2 JS is the fastest dynamic language.

my advise would be to send the data from your python backend in JSON to your JS front end, and you will get the best of both worlds.

CodePudding user response:

While it is possible to run Python in a browser (see MoRe's answer), it's going to be very slow and difficult, because Python isn't meant to be run in a browser. It would be easier to run Python on a server (try the flask or django libraries) and talk to it using JavaScript (e.g., using a REST API; here's a tutorial on implementing one in Flask). Modern internet speeds are fast enough that doing it on a server would likely be faster.

CodePudding user response:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
    <py-script> 
        print('Now you can!')
     </py-script>
</body>
</html>
  • Related