Spaces:
Sleeping
Sleeping
Delete login.py
Browse files
login.py
DELETED
@@ -1,111 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
import json
|
3 |
-
|
4 |
-
import requests
|
5 |
-
import time
|
6 |
-
from twocaptcha import TwoCaptcha
|
7 |
-
from cairosvg import svg2png
|
8 |
-
# two cap tcha API密钥
|
9 |
-
api_key = '50c4d9078bc12ca8c101f0900ec0c80f'
|
10 |
-
captcha_image_save = 'captcha.png'
|
11 |
-
# 定义请求头信息
|
12 |
-
headers = {
|
13 |
-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
|
14 |
-
}
|
15 |
-
account,password = "[email protected]","17331160967a"#还有一个3357的,过期换
|
16 |
-
|
17 |
-
def current_milli_time():
|
18 |
-
return round(time.time() * 1000)
|
19 |
-
|
20 |
-
|
21 |
-
session = requests.Session()
|
22 |
-
session.verify =False
|
23 |
-
|
24 |
-
session.headers = headers
|
25 |
-
|
26 |
-
# #传入账号密码获取返回结果的响应头从而得到cookie和截止时间
|
27 |
-
def get_response_headers(account:str,password:str,captcha_text:str):
|
28 |
-
login_url = 'https://jingling.bifangpu.com/user/v1/login'
|
29 |
-
payload = {
|
30 |
-
"email": account,
|
31 |
-
"password": password,
|
32 |
-
"captcha": captcha_text
|
33 |
-
}
|
34 |
-
|
35 |
-
response = session.post(login_url, data=payload)
|
36 |
-
|
37 |
-
# 获取响应头
|
38 |
-
headers = response.headers
|
39 |
-
print(headers)
|
40 |
-
return headers
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
def get_cur_captcha(timeStamp:int,solver)->'返回当前时间戳对应的验证码数字结果 或者 None':
|
48 |
-
geetest_base ='https://jingling.bifangpu.com/user/v1/captcha?t='
|
49 |
-
geetest_image_url = geetest_base+str(timeStamp)#这个只要请求了那么最新的验证码就是这个,并且自己写时间戳不影响截止时间
|
50 |
-
img_resp= session.get(geetest_image_url)
|
51 |
-
if img_resp.status_code==200:
|
52 |
-
img_content = img_resp.content
|
53 |
-
svg2png(img_content, write_to=captcha_image_save)
|
54 |
-
|
55 |
-
id = solver.send(file=captcha_image_save)
|
56 |
-
finalText = None
|
57 |
-
for i in range(5):
|
58 |
-
try:
|
59 |
-
time.sleep(10)
|
60 |
-
finalText = solver.get_result(id)
|
61 |
-
break
|
62 |
-
except Exception as e:
|
63 |
-
print(e)
|
64 |
-
if finalText and type(finalText) == str:
|
65 |
-
print("验证码处理成功")
|
66 |
-
print(finalText)
|
67 |
-
return finalText
|
68 |
-
else:
|
69 |
-
print('保存captcha图片失败')
|
70 |
-
return None
|
71 |
-
|
72 |
-
# def cookies_from_json_to_cookiejar(cookie:dict):
|
73 |
-
# # {'jinglingpan:sessid': '608c4163-16fd-4326-8caf-7b4076fdcaca',
|
74 |
-
# # 'jinglingpan:sessid.sig': 'qEDpK0oDIYLJXZbO1P7UjmJ0OjY'}
|
75 |
-
# return requests.utils.cookiejar_from_dict(cookie)
|
76 |
-
#
|
77 |
-
# def cookies_from_cookiejar_to_json(cookie)->dict:
|
78 |
-
# return requests.utils.dict_from_cookiejar(session.cookies)
|
79 |
-
|
80 |
-
|
81 |
-
def get_cookie_alive_str():
|
82 |
-
|
83 |
-
current_timestamp = current_milli_time()
|
84 |
-
solver = TwoCaptcha(api_key)
|
85 |
-
result = get_cur_captcha(current_timestamp, solver)
|
86 |
-
if result:
|
87 |
-
resp_headers = get_response_headers(account, password, result)
|
88 |
-
set_cookies = resp_headers['Set-Cookie']
|
89 |
-
print('#截止时间信息:', set_cookies)
|
90 |
-
# 单引号就可以
|
91 |
-
print('cookie=' + json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
92 |
-
return '#截止时间信息:'+ set_cookies+'\n'+'cookie=' + json.dumps(requests.utils.dict_from_cookiejar(session.cookies))
|
93 |
-
else:
|
94 |
-
return ''
|
95 |
-
if __name__ == '__main__':
|
96 |
-
|
97 |
-
current_timestamp = current_milli_time()
|
98 |
-
solver = TwoCaptcha(api_key)
|
99 |
-
result = get_cur_captcha(current_timestamp,solver)
|
100 |
-
if result:
|
101 |
-
resp_headers = get_response_headers(account,password,result)
|
102 |
-
set_cookies = resp_headers['Set-Cookie']
|
103 |
-
print('#截止时间信息:',set_cookies)
|
104 |
-
#单引号就可以
|
105 |
-
print('cookie='+json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|