|
| 1 | +#Python3.7 |
| 2 | +#encoding = utf-8 |
| 3 | + |
| 4 | +import execjs,requests,time |
| 5 | + |
| 6 | +class User():#获取用户密码加密 |
| 7 | + |
| 8 | + def __init__(self,user_id,user_password): |
| 9 | + |
| 10 | + self.user_id = user_id |
| 11 | + self.user_password = user_password |
| 12 | + self.session = requests.session() |
| 13 | + self.session.headers = { |
| 14 | + 'Referer':'https://dl.reg.163.com/webzj/v1.0.1/pub/index_dl2_new.html?cd=https%3A%2F%2Ftemp.163.com%2Fspecial%2F00804C4H%2F&cf=urs_style_2019.css%3Ft%3D20190527&MGID=1590637061742.5342&wdaId=&pkid=MODXOXd&product=163', |
| 15 | + 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36', |
| 16 | + #请在此处输入你的Cookie |
| 17 | + #参考链接 https://www.163.com/ |
| 18 | + } |
| 19 | + |
| 20 | + def get_pw(self): |
| 21 | + |
| 22 | + with open('pw.js','r',encoding='utf-8') as f: |
| 23 | + content = f.read() |
| 24 | + |
| 25 | + js_data = execjs.compile(content)#编译js |
| 26 | + pw = js_data.call('get_pw',self.user_password)#调用get_pw函数 |
| 27 | + return pw |
| 28 | + |
| 29 | + def get_rtid(self): |
| 30 | + |
| 31 | + with open('rtid.js','r',encoding='utf-8') as f: |
| 32 | + content = f.read() |
| 33 | + |
| 34 | + js_data = execjs.compile(content)#编译js |
| 35 | + rtid = js_data.call('get_rtid')#调用get_rtid函数 |
| 36 | + return rtid |
| 37 | + |
| 38 | + def get_tk(self,rtid): |
| 39 | + |
| 40 | + url = 'https://dl.reg.163.com/dl/gt' |
| 41 | + |
| 42 | + params = { |
| 43 | + 'un':self.user_id, |
| 44 | + 'pkid':'MODXOXd', |
| 45 | + 'pd':'163', |
| 46 | + 'channel':'0', |
| 47 | + 'topURL':'https://www.163.com/', |
| 48 | + 'rtid':rtid, |
| 49 | + 'nocache':int(time.time()*1000), |
| 50 | + } |
| 51 | + |
| 52 | + html = self.session.get(url,params = params).json() |
| 53 | + return html['tk'] |
| 54 | + |
| 55 | + def get_login(self,pw,rtid,tk): |
| 56 | + |
| 57 | + url = 'https://dl.reg.163.com/dl/l' |
| 58 | + |
| 59 | + |
| 60 | + data = { |
| 61 | + 'channel':'0', |
| 62 | + 'd':'10', |
| 63 | + 'domains':"163.com", |
| 64 | + 'l':'0', |
| 65 | + 'pd':"163", |
| 66 | + 'pkid':"MODXOXd", |
| 67 | + 'pw':pw, |
| 68 | + 'pwdKeyUp':'1', |
| 69 | + 'rtid':rtid, |
| 70 | + 't':int(time.time()*1000), |
| 71 | + 'tk':tk, |
| 72 | + 'topURL':"https://www.163.com/", |
| 73 | + 'un':self.user_id, |
| 74 | + } |
| 75 | + |
| 76 | + html = self.session.post(url,json = data).json()#传递JSON |
| 77 | + return html |
| 78 | + |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + |
| 82 | + user = User('请输入你的账号','请输入你的密码') |
| 83 | + pw = user.get_pw()#获取pw |
| 84 | + rtid = user.get_rtid()#获取rtid |
| 85 | + |
| 86 | + tk = user.get_tk(rtid)#获取tk |
| 87 | + |
| 88 | + login = user.get_login(pw,rtid,tk) |
| 89 | + print(login) |
| 90 | + |
| 91 | + |
0 commit comments