zoukankan      html  css  js  c++  java
  • Python代码调用JS函数

    采集过程中,遇到了一个token是经过JS加密生成的,于是乎进行JS断点追踪,生成了完整的生成token值的JS函数文件。

    这个JS函数需要在Python代码中调用,通过输入一个参数,然后会输出一个token值。

    所需模块:

      pip install pyexecjs

      注意:这里安装的模块叫:pyexecjs, 但是调用的时候的名字是:execjs

    具体调用步骤:

    # -*- coding: utf-8 -*-
    
    import execjs
    
    def get_js():
        # f = open("./../js/my.js", 'r', encoding='utf-8') # 打开JS文件
        f = open("tongchengJS.js", 'r', encoding='utf-8') # 打开JS文件
        line = f.readline()
        htmlstr = ''
        while line:
            htmlstr = htmlstr+line
            line = f.readline()
        return htmlstr
    
    
    def get_des_psswd(e):
        js_str = get_js()
        ctx = execjs.compile(js_str) #加载JS文件
        return (ctx.call('antitoken', e))  #调用js方法  第一个参数是JS的方法名,后面的data和key是js方法的参数
    
    
    if __name__ == '__main__':
        print(get_des_psswd(e='1570243707293'))

    参考:https://www.cnblogs.com/linlang781/p/8868496.html

  • 相关阅读:
    zoj1137 poj1466
    poj3041
    zoj1455
    hdu1160 FatMouse's Speed
    zoj2770
    hdu1469
    hdu3169
    Mapped exception to response: 500 (Internal Server Error)
    Mapped exception to response: 500 (Internal Server Error)
    object is not a function
  • 原文地址:https://www.cnblogs.com/yuanyongqiang/p/11625245.html
Copyright © 2011-2022 走看看