一、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.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

 

 

posted on 2020-02-18 00:24  心悦君兮君不知-睿  阅读(602)  评论(0编辑  收藏  举报