1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
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) 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) break else: print(data) break time.sleep(1) def get(self, ticket, smdl): 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()
|