简体   繁体   中英

How can I execute a .js file with python?

I'm looking to download and execute a node js (windows) application with python, but I can't seem to find a solution. This is my current code which works for files that are not .js

import requests
import subprocess

url = "directlink.com/jsfile.js"

r = requests.get(url)

with open("cmd.js", "wb") as f:
    f.write(r.content)

subprocess.call("cmd.js")

Any help highly appreciated.

you need to install the libraries js2py or requests-html to execute JavaScript from Python. go through this guide to learn more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM