-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcookie_check.py
94 lines (82 loc) · 2.13 KB
/
cookie_check.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
# @Author: GXR
# @CreateTime: 2022-01-20
# @UpdateTime: 2022-01-20
import json
import redis
import requests
from retrying import retry
import config
from cookie_api import app
red = redis.Redis(
host=config.REDIS_HOST,
port=config.REDIS_PORT,
db=config.REDIS_DB,
decode_responses=True,
)
@retry
def get_response(cookie):
config.HEADERS.update(
{
"pragma": "no-cache",
"cache-control": "no-cache",
"sec-ch-ua": '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
"sec-ch-ua-mobile": "?0",
"dnt": "1",
"upgrade-insecure-requests": "1",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"sec-fetch-site": "same-origin",
"sec-fetch-mode": "navigate",
"sec-fetch-user": "?1",
"sec-fetch-dest": "document",
"accept-language": "zh-CN,zh;q=0.9",
}
)
response = requests.get(
config.COOKIE_CHECK_URL, headers=config.HEADERS, cookies=json.loads(cookie)
)
if (
"pl_common_sassfilter" in response.text
or "login" in response.url
or "captcha" in response.url
or "passport" in response.url
):
return 0
elif response.status_code not in [
300,
301,
305,
400,
401,
402,
403,
404,
405,
406,
407,
408,
429,
450,
500,
501,
502,
503,
504,
]:
return 1
else:
return 0
# 检查cookie可用性
def cookie_check():
cookie_list = red.smembers(config.REDIS_KEY_COOKIE)
for cookie in cookie_list:
response = get_response(cookie)
if response == 1:
app.logger.info("[可用cookie]-[+1]")
else:
red.srem(config.REDIS_KEY_COOKIE, cookie)
app.logger.error("[删除cookie]-[+1]")
def run_cookie_check():
cookie_check()
if __name__ == "__main__":
run_cookie_check()