" />

欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python執(zhí)行js字符串常見方法示例

 更新時間:2022年04月12日 11:19:35   作者:Jeff的技術(shù)棧  
這篇文章主要為大家介紹了Python執(zhí)行js字符串常見方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪

方法

執(zhí)行大型js時有點慢

特殊編碼的輸入或輸出參數(shù)會出現(xiàn)報錯,解決方法:

可以把輸入或輸出的參數(shù)用base64編碼一下。base64都是英文和數(shù)字,沒有特殊字符了

1--js2py

pip insatll js2py
# 獲取執(zhí)行JS的環(huán)境
context = js2py.EvalJs()  
# 加載執(zhí)行
context.execute('放JS字符代碼')

2--execjs

import execjs
print(execjs.get().name)
# Node.js (V8)
import execjs
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}'
js_index = """
js
"""
# 打開js文件讀取
# new_url = execjs.compile(open("/Users/ts/Desktop/Jeff/今日頭條/new_sign.js").read()).call('get_sigtrue', url)  
# 讀取js字符串
new_url = execjs.compile(js_index).call('get_sigtrue', url)  
print(new_url)

3--execjs

import execjs
def get_js():
    f = open("./new_sign.js", 'r', encoding = 'UTF-8')
    line = f.readline()
    htmlstr = ''
    while line:
        htmlstr = htmlstr + line
        line = f.readline()
    return htmlstr
jsstr = 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))

以上就是Python執(zhí)行js字符串常見方法示例的詳細(xì)內(nèi)容,更多關(guān)于Python執(zhí)行js字符串的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論