[Python] 纯文本查看 复制代码 import json
import requests
import re
import time
COOKIE = "cookie信息"
DINGTALK_WEBHOOK = "YOUR_DINGTALK_WEBHOOK"
WXWORK_WEBHOOK = "YOUR_WXWORK_WEBHOOK"
SERVER_CHAN_KEY = "SCT242840T93gpF3423234BVisfJ0tfWjheR"#sever酱
UserAgent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
def main():
try:
if COOKIE is None:
print("COOKIE 环境变量未设置")
return
startTime = time.time()
cookie = COOKIE
sign_result = send_sign_in_request(cookie)
endTime = time.time()
print("耗时: {}ms".format(int((endTime - startTime) * 1000)))
print("签到结果: {}".format(sign_result))
publish_wechat(SERVER_CHAN_KEY, sign_result, int((endTime - startTime) * 1000))##推送信息函数
except Exception as e:
print(e)
def send_sign_in_request(cookie):
sign = get_sign_key(cookie)
url = "https://bbs.feiyeyu.com/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1&sign_as=1&inajax=1"
headers = {
"Cookie": cookie,
"User-Agent": UserAgent,
}
data = {
"formhash": sign,
"qdxq":"shuai"
}
response = requests.post(url, headers=headers, data=data, verify=False)
response_data = response.text#.encode().decode('unicode_escape').encode('utf-8').decode('utf-8')
pattern = re.compile(r'class="info"><li>([\s\S]*?)</li>')
match = pattern.search(response_data)
if match:
sign_results=match.group(1)
return sign_results
else:
pattern = re.compile(r'<div class="c">([\s\S]*?)</div>')
match = pattern.search(response_data)
if match:
sign_results = match.group(1).strip().replace('\r\n', '').strip()
return sign_results
else:
return "签到错误了哦"
def get_sign_key(cookie):
url = "https://bbs.feiyeyu.com/"
headers = {
"Cookie": cookie,
"User-Agent": UserAgent
}
response = requests.get(url, headers=headers, verify=False)
response_text = response.text
if "立即注册" in response_text:
raise Exception("cookie失效")
pattern = re.compile(r'formhash=(\w+)">退出')
match = pattern.search(response_text)
if match:
sign_value = match.group(1)
print("Sign的值是: {}".format(sign_value))
return sign_value
else:
raise Exception("未能获取sign,请检查cookie是否失效")
def publish_wechat(server_chan_key, sign_result_vo, duration):
if server_chan_key is None:
print("SERVER_CHAN 未设置")
return
title = sign_result_vo
if duration is not None:
title += f",耗时 {duration}ms"
try:
url = f"https://sc.ftqq.com/{server_chan_key}.send"
params = {
"text": title,
"desp": duration
}
response = requests.get(url, params=params)
response.raise_for_status()
except Exception as e:
print(e)
# 其他方法的定义,如 generate_dynamic_key, simple_encrypt, publish_wechat 等
if __name__ == "__main__":
main()
|