zoukankan      html  css  js  c++  java
  • Python爬虫连载8-JS加密(一)

    一、JS加密

    1.有的反爬虫策略采用js对需要传输的数据进行加密处理。

    2.经过加密,传输的就是密文

    3.加密函数或者过程一定是在浏览器完成,也就是一定会把代码(js代码)暴露给使用者

    4.通多阅读加密算法,就可以模拟出加密过程,从而达到破解。

    5.举一个案例

    """
    
    破解有道词典
    
    """
    
    from urllib import request,parse
    
    ​
    
    def youdao(key):
    
        url = "http://www.fanyi,com/translate_o?smartresult=dict&smartresult=rule"
    
        data = {
    
            "i":"girl",
    
            "from":"AUTO",
    
            "to":"AUTO",
    
            "smartresult":"dict",
    
            "client":"fanyideskweb",
    
            "salt":"1523100789519",
    
            "sign":"b8a55a436686cd89873fa46514ccedbe",
    
            "doctype":"json",
    
            "version":"2.1",
    
            "keyfrom":"fanyi.web",
    
            "action":"FY_BY_REALTIME",
    
            "typeResult":"False"
    
        }
    
    ​
    
        data = parse.urlencode(data).encode()
    
        headers = {
    
            "Connection": "keep - alive",
    
            "Content - Encoding":"gzip",
    
            "Content - Language": "zh - CN",
    
            "Content - Type": "text / html",
    
            "charset":"utf - 8",
    
            "Date": "Mon, 17 Feb 2020 15: 23:36 GMT",
    
            "Server":"nginx",
    
            "Transfer - Encoding": "chunked",
    
            "Vary": "Accept - Encoding"
    
        }
    
        req = request.Request(url=url,data=data,headers=headers)
    
    ​
    
        rsp = request.urlopen(req)
    
    ​
    
        html = rsp.read().decode()
    
        print(html)
    
    ​
    
    if __name__ == "__main__":
    
        # for i in range(10000):
    
        #     print(sum)
    
    youdao(45)

    二、源码

    Reptitle8_1_JSEncryption.py

    https://github.com/ruigege66/PythonReptile/blob/master/Reptitle8_1_JSEncryption.py

    2.CSDN:https://blog.csdn.net/weixin_44630050

    3.博客园:https://www.cnblogs.com/ruigege0000/

    4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

     

  • 相关阅读:
    [转]群控电梯调度算法
    [转] 电梯调度算法总结
    [转]grub2.0和之前版本修复解决方案
    [转]Ubuntu 10.04 编译安装最新版本Linux2.6.34内核
    [转]PS2 键盘工作方式
    [转]个人管理 - 目标管理之前,你会时间管理吗
    [转]ubuntu 下编译内核简单步骤
    [转]关闭Google安全搜索,实现无限制搜索
    [转]Vim 复制粘贴探秘
    [转]Linux文件搜索
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/12324518.html
Copyright © 2011-2022 走看看