# -*- 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('tt请确认登陆') # 请再手机端确认登陆 elif data.get('code') == 205: print('ttt干嘛取消登陆了') 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): # 获取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()
python教程
Python京东扫码获取Cookie方法
python教程
我的站长站
2021-09-29
共93人阅读
最新更新
-
01python批量获取百度云用户份信息 2个月前
-
02小写金额转大写金额Python代码 2个月前
-
03python自动将图片复刻到excel表格代码 2个月前
-
04分享三种Python批量图片添加随机水印方法 4个月前
-
05Python爬取blog文章内容代码 4个月前
热门推荐
-
01123网盘解析下载python脚本 438热度
-
02Python和彩云自动签到云函数脚本分享 362热度
-
03基于百度API文字转语音Python示例代码 295热度
-
04Python无需认证QQ扫码登录脚本 291热度
-
05Python自动下载歌曲宝音乐和歌词脚本 282热度