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,sysimport timefrom notify import senddef pr(message):msg.append(message+ "\n")print(message)msg = []def index(cookie):url = 'https://www.haidan.video/index.php'header = {"authority": "www.haidan.video","method": "GET","path": "/index.php","referer":"https://www.haidan.video/torrents.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)time.sleep(3)info = response.textif "首页" in info:pr("登陆成功")signin(cookie)else:pr("登录失败,等待10秒后重试")time.sleep(10)signin(cookie)except Exception as e:pr("登录失败,请检查cookie是否正确")def signin(cookie):url = 'https://www.haidan.video/signin.php'header = {"authority": "www.haidan.video","method": "GET","path": "/signin.php","referer":"https://www.haidan.video/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","cookie":cookie}try:response = requests.get(url=url,headers=header)time.sleep(3)if response.status_code == 200:torrents(cookie)else:pr("打卡失败?")except Exception as e:pr("登录失败")def torrents(cookie):url = 'https://www.haidan.video/torrents.php'header = {"authority": "www.haidan.video","method": "GET","path": "/torrents.php","referer":"https://www.haidan.video/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.texttime.sleep(3)if "已经打卡" in info:pattern = re.compile(r"class='VeteranUser_Name'><b>(.+?)</b>")pattern2 = re.compile(r'分享率: </font> (.*?) ')pattern3 = re.compile(r'<span id="(.*)">(.*?)</span>')pattern4 = re.compile(r'上传量: </font> (.*?) ')pattern5 = re.compile(r'下载量: </font> (.*?) ')matches = pattern.findall(info)matches1 = pattern2.findall(info)matches2 = pattern3.findall(info)matches3 = pattern4.findall(info)matches4 = pattern5.findall(info)if not matches or not matches1 or not matches2 or not matches3 or not matches4:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnpr( "用户名:" + matches[0] + " 魔力值:" + matches2[0][1] + " 分享率" + matches1[0] + " 上传量" + matches3[0] + " 下载量" + matches4[0])else:pr("查询失败")except Exception as e:pr("登陆失败")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_haidan")si_cookie = getattr(config, 'wy_haidan', '')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_haidan='' 或在 config.py 中设置 wy_haidan")sys.exit()except Exception as e:pr("请设置变量 export wy_haidan='' 或在 config.py 中设置 wy_haidan")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访问www.haidan.video,完成签到(signin.php),随后在torrents.php页面校验"已经打卡",并抓取用户名 / 魔力值 / 分享率 / 上传量 / 下载量等信息。多账号与定时通知:支持从环境变量或
config.py读取多账号cookie(以换行、&、@分隔),逐个执行并通过notify.send推送结果;示例cron: 10 9 * * *每天 09:10 运行。
主要方法
pr(message):统一打印并写入全局msg,便于最终汇总推送。index(cookie):以cookie访问index.php验证登录是否成功;成功则进入signin(cookie);失败会等待 10 秒后仍调用signin(相当于继续尝试签到)。signin(cookie):访问signin.php触发签到;状态码为 200 则继续到torrents(cookie)做结果校验与信息抓取。torrents(cookie):访问torrents.php;若页面包含"已经打卡",用正则提取并输出用户名(VeteranUser_Name)、分享率、<span id="...">中的魔力值、以及上传量 / 下载量;否则提示查询失败。sicxs()(入口/调度):创建或加载config.py;合并读取wy_haidan(环境变量与配置文件);按分隔符切分多账号循环执行index();每个账号执行完调用send("海胆PT站", ''.join(msg))推送并清空日志。
账号配置:
wy_haidan="cookieA&cookieB@cookieC"或多行分隔均可。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论