Python爬蟲連載8-JS加密(一)

1、JS加密html

1.有的反爬蟲策略採用js對須要傳輸的數據進行加密處理。nginx

2.通過加密,傳輸的就是密文git

3.加密函數或者過程必定是在瀏覽器完成,也就是必定會把代碼(js代碼)暴露給使用者github

4.通多閱讀加密算法,就能夠模擬出加密過程,從而達到破解。web

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)

 

 

2、源碼json

Reptitle8_1_JSEncryption.py瀏覽器

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

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

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

4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料

 

相關文章
相關標籤/搜索