Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Python libraries that can manipulate JavaScript

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces what you can operate JavaScript Python library, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Preface

We all know that Python can easily achieve certain functions, and can also write web pages, such as Remi,Pysimplegui, but it is the first time I have heard of JavaScript as a scripting language for browsers, and it is also the first time for editors to hear about it, so I will supplement this knowledge with you.

1. PyExecJS

Is a Python module that can execute JavaScript scripts, and can interact with JavaScript on the web page, so that you can get more accurate access to the encrypted content of the web page. If you use the network module in Python for request, you will not be able to decrypt the encrypted content in the document. At this time, you can easily decrypt the encrypted content of the web page using our PyExecJS. Of course, you have to reverse the Js. However, if there is nothing wrong with PyExecJS parsing JS statements, you still need the entire Js language parsing environment. NodeJS is recommended here, which is embarrassing. Let's look at the use of PyExecJs:

1. The general operation import execjs aa=execjs.eval ("'one | two | three'.split (' |')") # executes the JavaScript code to split the string into an array print (aa) e=execjs.compile ('# compile an expression function add (XMague y) {return xscene;}'') print (e.call ('add',10,20)) # calls the compiled function and assigns a value

You can also run our statement by getting the engine, as follows:

Print (execjs.get (). Eval ('1x 1')) 2. Check out the interpretation engine print (execjs.get (). Name)

Here the interpretation engine of JavaScript is JScript, and we can also use our own specified engine, such as "Nodejs".

3. Specify engine import execjs import os os.environ ["EXECJS_RUNTIME"] = "Node" print (execjs.get () .name)

You can also specify the engine manually, as follows:

Js1=execjs.get (execjs.runtime_names.JScript) print (js1.eval ('1')) js2=execjs.get (execjs.runtime_names.Node) print (js2.eval ('2'))

II. Js2Py

I think this is better, it can be said to be a synthesis, it does not need to rely on other environments, it can run Js files independently, but its running speed may be a little slower, but this is not a big deal. Let's take a look at what artifact functions it has.

1. Routine operation, necessary

two。 Loop through import js2py aa=js2py.eval_js (''var iTuno; for (var centering 1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report