1、JS加密之「鹽」git
1.salt屬性「鹽":多用於密碼學,好比咱們的銀行卡是六位密碼,可是實際上在銀行的系統裏,咱們輸入密碼後,會給原始的密碼添加若干字符,造成更加難以破解的密碼。這個過程咱們稱爲」加鹽「。github
""" 處理JS加密 """ import time,random def getSalt(): """ salt公式:"" + ((new Date).getTime() + parseInt(10 *Matn.rnandom(),10)) :return: """ salt = int(time.time()*1000) + random.randint(0,10) return salt def getMD5(): import hashlib md5zhi = hashlib.md5() md5zhi.update(v.encoding="uft-8") sign = md5zhi.hexdigest() return sign if __name__ == "__main__": getSalt() getMD5()
2、ajax請求ajax
1.異步請求;json
2.必定會有url,請求方法,可能有數據瀏覽器
3.通常使用json格式微信
4.案例:爬取豆瓣電影dom
""" 爬取豆瓣電影排行榜 """ from urllib import request import json url = "https://movie.douban.com/typerank?type_name=%E5%89%A7%E6%83%85&type=11&interval_id=100:90&action=" rsp = request.urlopen(url) data = rsp.read().decode() data = json.loads(data) print(data)
這裏報錯了,是由於豆瓣有反爬蟲機制,咱們修改代碼,把Python假裝成一個瀏覽器進行訪問異步
""" 爬取豆瓣電影排行榜 """ from urllib import request import json url_u = "https://movie.douban.com/typerank?type_name=%E5%89%A7%E6%83%85&type=11&interval_id=100:90&action=" headers = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36" } url = request.Request(url_u,headers=headers) rsp = request.urlopen(url) data = rsp.read().decode() print(data)
3、源碼學習
Reptitle9_1_JSEncryption.py大數據
Reptitle9_2_ajaxResponse.py
https://github.com/ruigege66/PythonReptile/blob/master/Reptitle8_1_JSEncryption.py
https://github.com/ruigege66/PythonReptile/blob/master/Reptitle9_2_ajaxResponse.py
2.CSDN:https://blog.csdn.net/weixin_44630050
3.博客園:https://www.cnblogs.com/ruigege0000/
4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料