简体   繁体   English

从 Python 调用 JavaScript(第 3 方库)

[英]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.我已经搜索了很多,但现在得出了明确的结论,因为一些项目(pyv8)似乎已经死了,我不确定这是否合适。 The 3rd part lib requires a DOM, eg.第三部分 lib 需要一个 DOM,例如。 a container element in which it runs.它运行的容器元素。 It also uses web assembly and in general is pretty heavy.它还使用 web 组件,一般来说很重。

Not sure if libs like pyv8 would actually be suitable for that.不确定像 pyv8 这样的库是否真的适合。 Other approach would be to go with selenium and headless chrome or a local node.js service but both of these sound very heavy.其他方法是使用 go 和 selenium 和无头镀铬或本地 node.js 服务,但这两种服务听起来都很沉重。 Oh, and the lib must work in windows as that's simply company policy, windows servers so PyMiniRacer is out.哦,该库必须在 windows 中工作,因为这只是公司政策,windows 服务器因此 PyMiniRacer 出局了。

What are my other options?我还有哪些其他选择?

Consider taking a look at this post: How do I call a Javascript function from Python?考虑看看这篇文章: 如何从 Python 调用 Javascript function? . .

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.但是,如果您的目标是出于网页抓取等原因访问网页中的 JS 代码,您也可以考虑使用selenium webdriver + python来执行此操作。 Take a look at this medium.com post: How to Run JavaScript in Python | medium.com这个中。 Web Scraping | Web 刮痧 | Web Testing Web 测试

Other Resources :其他资源

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

PS: I am not sure if this would help you. PS:我不确定这是否会帮助你。 There is another library ( PyExecJS ) which is maintained no longer;还有一个不再维护的库( PyExecJS ); but I think you have looked it up already.但我想你已经查过了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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