前天看到一个有趣的东西Python扫码登录京东源码,让我以为是京东移动端的登录,测试后发现是PC端的,PC端的拿来有个屁用啊,分享给大家,记录在此,以后说不定能用上呢!
复制
# -*- coding: utf-8 -*- import requests import time import re import json def loads_jsonp(_jsonp): try: return json.loads(re.match(".*?({.*}).*", _jsonp, re.S).group(1)) except: raise ValueError('Invalid Input') class jdthor: def qrcode(self): # 保存二维码 url = "https://qr.m.jd.com/show?appid=133&size=147" req = requests.get(url) with open("wc.png", mode="wb") as f1: f1.write(req.content) # print(req.headers) self.state(req.cookies.get_dict()) def state(self, h): # 查看扫码情况 while True: smdl = h.get('wlfstk_smdl') codekey = h.get('QRCodeKey') headers = { "Referer": "https://union.jd.com/index", "Cookie": f"QRCodeKey={codekey}; wlfstk_smdl={smdl}" } url = f'https://qr.m.jd.com/check?appid=133&token={smdl}&callback=jsonp' req = requests.get(url, headers=headers) data = loads_jsonp(req.text) if data.get('code') == 201: print('\t还没扫描呢亲~') # 未扫描 elif data.get('code') == 202: print('\t\t请确认登陆') # 请再手机端确认登陆 elif data.get('code') == 205: print('\t\t\t干嘛取消登陆了') break # 取消登陆 elif data.get('code') == 203: print('已经过期了') break elif data.get('code') == 200: self.get(data.get('ticket'), smdl) print(data) break else: print(data) break time.sleep(1) def get(self, ticket, smdl): # 获取Ck url = f'https://passport.jd.com/uc/qrCodeTicketValidation?t={ticket}&ReturnUrl=https://union.jd.com/index&callback=jsonp' headers = { "Referer": "https://union.jd.com/index", "Cookie": f"wlfstk_smdl={smdl}" } req = requests.get(url, headers=headers) ckdict = req.cookies.get_dict() print(ckdict) if __name__ == '__main__': jd = jdthor() jd.qrcode()
执行上面的代码后会在当前目录下生成一个名为wc.png的二维码图片(名字随便你改),手动打开扫码就行了。
评论 (0)