1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/Bg6shY若失效,可用地址
阿里云:
服务器购买地址
https://t.aliyun.com/U/Bg6shY若失效,可用地址
https://www.aliyun.com/daily-act/ecs/activity_selection?source=5176.29345612&userCode=49hts92d腾讯云:
https://curl.qcloud.com/wJpWmSfU若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=2019052.部署教程
3.代码如下
# cron: 10 9 * * *import requestsimport re,os,sysfrom notify import senddef pr(message):msg.append(message + "\n" )print(message)msg = []def index(cookie):url = 'https://pt.soulvoice.club/index.php'header = {"Connection": "keep-alive","authority": "pt.soulvoice.club","method": "GET","path": "/index.php","referer":"https://pt.soulvoice.club/attendance.php","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36","content-type": "text/html; charset=utf-8; Cache-control:private","cookie":cookie}try:response = requests.get(url=url,headers=header)info = response.textif "签到" in info:pr("账号登陆成功")if "签到已得" in info:pr("您今天已经签到过了,请勿重复刷新。")torrents(cookie)else:attendance(cookie)else:pr("登录失败,请检查cookie是否有效")except Exception as e:pr(e)def attendance(cookie):url = 'https://pt.soulvoice.club/attendance.php'header = {"Connection": "keep-alive","authority": "pt.soulvoice.club","method": "GET","path": "/attendance.php","referer":"https://pt.soulvoice.club/index.php","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36","content-type": "text/html; charset=utf-8; Cache-control:private","cookie":cookie}try:response = requests.get(url=url,headers=header)info = response.textif "签到已得" in info:pr("签到成功,请勿重复刷新。")torrents(cookie)else :pr("签到中...")attendance(cookie)except Exception as e:pr(e)def torrents(cookie):url = 'https://pt.soulvoice.club/torrents.php'header = {"Connection": "keep-alive","authority": "pt.soulvoice.club","method": "GET","path": "/torrents.php","referer":"https://pt.soulvoice.club/attendance.php","User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36","content-type": "text/html; charset=utf-8; Cache-control:private","cookie":cookie}try:response = requests.get(url=url,headers=header)pattern = re.compile(r"'><b>(.*?)</b></a></span>")pattern2 = re.compile(r'>使用</a>]: (.*) <a')pattern3 = re.compile(r'签到已得(.*?)\]</a>')matches = pattern.findall(response.text)matches1 = pattern2.findall(response.text)matches2 = pattern3.findall(response.text)if not matches or not matches1 or not matches2:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnpr( "用户名:" + matches[0] + " 魔力值:" + matches1[0] + " 签到已得:" + matches2[0])except Exception as e:pr(e)def sicxs():config_path = 'config.py'if os.path.exists(config_path):import configelse:with open(config_path, 'w') as f:pr("首次运行,已创建配置文件 config.py,请按照说明填写相关变量后再次运行脚本。")f.write('#可以在此文件中添加配置变量,例如:\nsfsy = ""\n')try:env_cookie = os.environ.get("wy_soulvoice")si_cookie = getattr(config, 'wy_soulvoice', '')if env_cookie and si_cookie:cookies = env_cookie + "\n" + si_cookieelif env_cookie:cookies = env_cookieelif si_cookie:cookies = si_cookieelse:pr("请设置变量 export wy_soulvoice='' 或在 config.py 中设置 wy_soulvoice")sys.exit()except Exception as e:pr("请设置变量 export wy_soulvoice='' 或在 config.py 中设置 wy_soulvoice")sys.exit()list_cookie = [c for c in re.split(r'\n|&', cookies) if c.strip()]total_cookies = len(list_cookie)for i, list_cookie_i in enumerate(list_cookie):print(f'\n----------- 账号【{i + 1}/{total_cookies}】执行 -----------')pr(f"账号【{i + 1}】开始执行:")try:index(list_cookie_i)except Exception as e:pr(f"执行账号【{i + 1}】时发生错误: {e}")finally:send("铃音", ''.join(msg))msg.clear()print(f'\n----------- 执 行 结 束 -----------')if __name__ == '__main__':sicxs()
该脚本为聆音自动签到脚本。
主要作用
自动签到:进入首页判断登录→访问
attendance.php完成签到;已签则直接跳过。账户信息回显:打开
torrents.php抓取用户名 / 魔力值 / 今日签到奖励并推送通知。多账号:
wy_soulvoice支持换行或&分割多个 cookie,逐个执行并逐个notify.send("铃音", …)。
主要方法
pr(msg):统一收集日志,便于单账号统一推送,随后清空。index(cookie):用首页index.php验证是否已登录(页面含"签到"字样),判断:已登录且页面含"签到已得"→已签;调用
torrents展示数据。已登录但未签→调用
attendance执行签到。否则判为登录失败(大概率 cookie 失效或保护页)。
attendance(cookie):访问attendance.php触发签到;若响应已出现"签到已得",视为成功并转到torrents;否则继续尝试。torrents(cookie):访问torrents.php,用 3 个正则提取用户名、魔力值、签到已得并打印。
注意事项
避免递归死循环
attendance()在未出现"签到已得"时会自调用;建议改为有限次循环重试(如最多 3 次,sleep(2, 4, 8)退避),超过上限打印"签到超时,可能站点延迟或需手动验证",然后继续后续流程(可直接进torrents做信息拉取,方便观测)。统一超时与异常处理
所有
requests.get增加timeout=10;except中打印status_code摘要(若有)与 URL,便于定位是哪一步失败。判定条件更稳
index()用"页面包含'签到'"判断已登录可能误判(例如未登录页也可能出现文字)。更稳妥做法:同时检查用户导航元素或退出链接(如包含"退出""个人中心"等),双条件通过才算登录。解析健壮性
在正则前先做多空白折叠(把连续空白替换为单空格),提升匹配成功率。
匹配失败时给出逐项兜底日志(分别提示"用户名解析失败/魔力值解析失败/奖励解析失败"),不要一次性笼统报错。
torrents()的 3 个正则对 HTML 空格与换行十分敏感(尤其pattern2)。建议:会话复用与指纹一致
你已在部分脚本用
requests.Session();这里也可 per-account 建一个Session,把公共头(UA、Referer)设进session.headers,减少重复粘贴,并复用连接以降低 403/超时概率。Cloudflare/重定向兼容
若站点偶发 302/JS 挑战,可在关键请求后打印最终 URL 与
response.history长度;如连续被重定向到登录页,直接判定 cookie 失效。日志与通知分级
在日志前加模块前缀:
[登录] …、[签到] …、[信息] …;失败时附简短原因。多账号时收到通知更一目了然。安全与风控
不要在日志中打印 cookie;多账号之间随机 sleep(1~3s),减少同 IP 同时触发的频率峰值。
配置兜底
读取环境变量后若为空字符串,应提示"未配置有效 cookie"并跳过而非退出整个程序,方便多容器/多任务混跑。
编码与语言环境
站点偶尔返回非 UTF-8 时可先
response.apparent_encoding再设response.encoding;解析失败时输出"编码异常,原始前256字节"帮助排查。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论