<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                Python中執行JS代碼,通常用兩個庫:js2py,pyexecjs。當網頁使用 js 加密時我們可以使用這些庫來分析 js 的實現邏輯,獲取加密信息。 <br/> js2py是純python實現的庫,用于在python中運行js代碼,本質上是將js代碼翻譯成python代碼來執行。 <br/> 安裝js2py庫:`pip install js2py` <br/> **1. 在python中執行js代碼** ```python import js2py log = js2py.eval_js('console.log("hello world")') # 'hello world' print(type(log)) # <class 'NoneType'> add = js2py.eval_js('function add(x, y){return x+y}') print(type(add)) # <class 'js2py.base.JsObjectWrapper'> print(add(10, 20)) # 30 # 也可以定義變量 add.n = {'class': 'Hello World!'} print(type(add.n)) # <class 'js2py.base.JsObjectWrapper'> print(add.n) # {'class': 'Hello World!'} ``` 或者: ```python import js2py # 1. 創建js環境 context = js2py.EvalJs() # 2. 定義js函數 add1 = context.execute('function add(x, y){return x+y}') print(add1) # None # 3. 調用js函數 result = context.add(10, 20) print(result) # 30 # 3. 可以定義變量 context.n = {'class': 'Hello World!'} print(type(context.n)) # <class 'js2py.base.JsObjectWrapper'> print(context.n) # {'class': 'Hello World!'} ``` <br/> **2. js代碼翻譯** ```python """ @Date 2021/3/19 """ import js2py # 將js代碼翻譯成Python腳本 print(js2py.translate_js("console.log('hello world')")) # 將js文件翻譯為python腳本 js2py.translate_file("test.js", 'test.py') ``` <br/> **3. 在js中調用Python函數** ```python """ @Date 2021/3/18 """ import js2py def add(x, y): return x+y # 1. 將python翻譯成js context = js2py.EvalJs({"add": add}) # 2. 調用函數 result = context.add(10, 20) print(type(result)) # <class 'int'> print(result) # 30 # 3. 或者通過 eval 函數調用 result2 = context.eval('add(10, 20)') print(result2) # 30 ``` <br/> **4. 在js中調用Python模塊** ```python """ @Date 2021/3/18 """ import js2py # 1. 使用pyimport導入Python的requests庫 js = """ pyimport requests console.log('導入成功'); var response = requests.get('http://www.baidu.com') console.log(response.url); console.log(response.text); """ # 2. 執行js代碼 js2py.eval_js(js) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看