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: 8 8 * * *import requestsimport re,timeimport os,sysfrom notify import senddef pr(message):msg.append(message + "\n")print(message)msg = []s = requests.session()def index(cookie):url = 'https://hdhome.org/index.php'header = {"Connection": "keep-alive","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","host":"hdhome.org","referer":"https://hdhome.org/torrents.php","cookie":cookie}try:response = s.get(url=url,headers=header)time.sleep(3)info = response.textif "首页" in info:pr("登陆成功")attendance(cookie)else:pr("登录失败")except Exception as e:pr(e)def attendance(cookie):url = 'https://hdhome.org/attendance.php'header = {"Connection": "keep-alive","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","host":"hdhome.org","referer":"https://hdhome.org/torrents.php","cookie":cookie}try:response = s.get(url=url,headers=header)time.sleep(3)info = response.textif "签到已得" in info:pr("签到成功,请勿重复刷新。")torrents(cookie)else :pr("签到中...")attendance(cookie)except Exception as e:pr(e)def torrents(cookie):url = 'https://hdhome.org/torrents.php'header = {"Connection": "keep-alive","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","host":"hdhome.org","referer":"https://hdhome.org","cookie":cookie}response = s.get(url=url,headers=header)time.sleep(3)pattern = re.compile(r"class='(.+?)'><b>(.+?)</b>")pattern2 = re.compile(r']: (.*) \(')pattern3 = re.compile(r'签到已得(.*?)\) ')pattern4 = re.compile(r'做种积分:</font>(.*?) ')matches = pattern.findall(response.text)matches1 = pattern2.findall(response.text)matches2 = pattern3.findall(response.text)matches3 = pattern4.findall(response.text)if not matches or not matches1 or not matches2 or not matches3:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnpr( "用户名:" + matches[0][1] + " 魔力值:" + matches1[0] + " 签到已得:" + matches2[0]+ " 做种积分:" + matches3[0])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_hdhome")si_cookie = getattr(config, 'wy_hdhome', '')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_hdhome='' 或在 config.py 中设置 wy_hdhome")sys.exit()except Exception as e:pr("请设置变量 export wy_hdhome='' 或在 config.py 中设置 wy_hdhome")sys.exit()list_cookie = re.split(r'\n|&|@', cookies)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("家园PT站", ''.join(msg))msg.clear()print(f'\n----------- 执 行 结 束 -----------')if __name__ == '__main__':sicxs()
解析
该脚本为家园 PT 站自动签到脚本。
主要作用
信息汇总:使用提供的
cookie访问hdhome.org,先校验是否登录成功,再进入attendance.php完成签到,随后到torrents.php抓取并输出用户名 / 魔力值 / 当日签到收益 / 做种积分等信息。多账号与通知:从环境变量或
config.py读取多个账号(以换行、&、@分隔),逐个执行并通过notify.send("家园PT站", …)推送每个账号的结果;cron: 8 8 * * *每天 08:08 运行。会话复用:用全局
requests.session()维持同一会话,提高稳定性。
主要方法
pr(message): 统一打印并写入全局msg列表,便于最终拼接通知内容。index(cookie): 访问index.php验证是否登录成功;成功则进入attendance(cookie),失败则提示。attendance(cookie): 访问attendance.php执行签到;若页面包含"签到已得"视为成功并进入torrents(cookie);否则打印"签到中..."并递归再次调用自身(轮询直到出现成功文案)。torrents(cookie): 访问torrents.php,用正则提取:class='…'><b>…</b>→ 用户名']: (.*) ('→ 魔力值'签到已得(…)\) '→ 当日签到收益'做种积分:</font>(…) '→ 做种积分
若匹配失败则提示"解析用户信息失败(可能页面改版或 cookie 失效)"。sicxs()(主入口/调度):初始化或创建
config.py;合并读取
wy_hdhome(环境变量与config.py同名变量);拆分多账号循环执行
index();每个账号执行完发送一次通知并清空
msg。
小提示
attendance()使用递归轮询,建议加上最大重试/睡眠间隔改为while循环,避免异常情况下长时间递归。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论