What are the methods for Python to execute js strings
This article mainly explains the "Python implementation of js strings what are the methods", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "what are the methods of Python execution of js strings"!
Method
It is a little slow to execute large js
Specially coded input or output parameters will report an error, the solution:
You can encode the input or output parameters in base64. Base64 is in English and numbers, and there are no special characters.
1--js2pypip insatll js2py# gets the environment context = js2py.EvalJs () # load executes context.execute ('put JS character code') 2--execjsimport execjsprint (execjs.get () .name) # Node.js (V8) import execjsuser_id = '3232597584'url = f' https://www.toutiao.com/toutiao/api/pc/feed/?min_behot_time=1588149898&category=__all__&utm_source=toutiao&widen=1&tadrequire=true&user_id={ User_id} & visited_uid= {user_id} 'js_index = "js"# Open the js file to read # new_url = execjs.compile (open (" / Users/ts/Desktop/Jeff/ Jinri Toutiao / new_sign.js "). Read ()) .call (' get_sigtrue' Url) # read the js string new_url = execjs.compile (js_index) .call ('get_sigtrue', url) print (new_url) 3--execjsimport execjsdef get_js (): F = open (". / new_sign.js",' r' Encoding = 'UTF-8') line = f.readline () htmlstr =' 'while line: htmlstr = htmlstr + line line = f.readline () return htmlstrjsstr = get_js () ctx = execjs.compile (jsstr) user_id =' 3232597584'url = f 'https://www.toutiao.com/toutiao/api/pc/feed/?min_behot_time=1588149898&category=__all__&utm_source=toutiao&widen=1&tadrequire=true&user_id={ User_id} & visited_uid= {user_id} 'print (ctx.call (' getUrl') Url) Thank you for your reading The above is the content of "what are the methods for Python to execute js strings?" after the study of this article, I believe you have a deeper understanding of the method of executing js strings in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!