简体   繁体   中英

Call JavaScript (3rd party library) from Python

I've already searched quite a bit but came to now clear conclusion as some projects (pyv8) seem to be dead and I'm not sure if that is suitable at all. The 3rd part lib requires a DOM, eg. a container element in which it runs. It also uses web assembly and in general is pretty heavy.

Not sure if libs like pyv8 would actually be suitable for that. Other approach would be to go with selenium and headless chrome or a local node.js service but both of these sound very heavy. Oh, and the lib must work in windows as that's simply company policy, windows servers so PyMiniRacer is out.

What are my other options?

Consider taking a look at this post: How do I call a Javascript function from Python? .

However , if your objective is to access JS code in a webpage for reasons such as webscraping, you could also consider using selenium webdriver + python to do so. Take a look at this medium.com post: How to Run JavaScript in Python | Web Scraping | Web Testing

Other Resources :

  1. https://www.quora.com/How-do-we-use-JavaScript-with-Python
  2. Python to JS: https://pypi.org/project/javascripthon/

PS: I am not sure if this would help you. There is another library ( PyExecJS ) which is maintained no longer; but I think you have looked it up already.

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