python代码京东扫码获取Cookie 仅70行

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

# -*- 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)
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代码京东扫码获取Cookie 仅70行

🔞本文链接: https://193.gs/pyjdcookie/index.html

🌡️本文总热度