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: 20 8 * * *import requestsimport re,timeimport os,sys,jsonfrom notify import senddef pr(message):msg.append(message + "\n" )print(message)msg = []def index(cookie): #登录url = "https://bbs.ijingyi.com/plugin.php"params = {'id': "dsu_paulsign:sign"}headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0",'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.7",'cache-control': "max-age=0",'sec-ch-ua': "\"Microsoft Edge\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"",'sec-ch-ua-mobile': "?0",'sec-ch-ua-platform': "\"Windows\"",'upgrade-insecure-requests': "1",'sec-fetch-site': "none",'sec-fetch-mode': "navigate",'sec-fetch-user': "?1",'sec-fetch-dest': "document",'accept-language': "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",'priority': "u=0, i",'Cookie': cookie,}response = requests.get(url=url,headers=headers,params=params)response.encoding = "utf-8"info = response.textif "<em>登录</em></button></td>" in info:pr("cookie失效或错误")else:pr("账号登陆成功")time.sleep(3)if "您今日已经签到" in info:url = "https://bbs.ijingyi.com/plugin.php"response = requests.get(url=url,headers=headers)response.encoding = "utf-8"info = response.textpattern = re.compile(r'uid=(.*?)" target="_blank" title="访问我的空间">(.*?)</a>')matches = pattern.findall(info)if not matches :pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnid = matches[0][0]pr("今日已完成签到,无需重复签到")infoo(id,headers)returnpattern = re.compile(r'uid=(.*?)" target="_blank" title="访问我的空间">(.*?)</a>')pattern1 = re.compile(r'formhash=(.*?)">退出</a>')matches = pattern.findall(info)matches1 = pattern1.findall(info)if not matches or not matches1 :pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnpr(f"用户名: {matches[0][1]}")hash = matches1[0]id = matches[0][0]qiandao(hash, headers)time.sleep(3)infoo(id,headers)def infoo(id,headers):#我的信息url = f"https://bbs.ijingyi.com/home.php?mod=space&uid={id}&do=profile&from=space"response = requests.get(url=url,headers=headers)response.encoding = "utf-8"info = response.textpattern = re.compile(r'<li><em>积分</em>(.*?)</li>')pattern1 = re.compile(r'<li><em>精币</em>(.*?)</li>')pattern2 = re.compile(r'<li><em>荣誉</em>(.*?)</li>')pattern3 = re.compile(r'<h2>该会员签到详情</h2><p>累计签到总天数 : <b>(.*?)</b> 天</p><p>连续签到天数 : <b>(.*?)</b> 天</p><p>本月签到天数 : <b>(.*?)</b> 天')matches = pattern.findall(info)matches1 = pattern1.findall(info)matches2 = pattern2.findall(info)matches3 = pattern3.findall(info)if not matches or not matches1 or not matches2 or not matches3:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnpr(f"积分: {matches[0]} 精币: {matches1[0]} 荣誉: {matches2[0]} 签到累计天数: {matches3[0][0]} 本月签到天数: {matches3[0][2]} 连续签到天数: {matches3[0][1]} ")def qiandao(hash, headers):url = "https://bbs.ijingyi.com/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1"data = {'formhash': hash,"submit": "1","targerurl": "","todaysay": "","qdxq": "kx"}try:response = requests.post(url=url, headers=headers, data=data)response.encoding = "utf-8"info = json.loads(response.text)if info['status'] == 1:pr(f"签到成功,连续签到 {info['data']['mdays']} 天")else:pr(f"签到失败: {info}")except Exception as e:pr(f"签到过程中发生未知错误: {str(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_jylt")si_cookie = getattr(config, 'wy_jylt', '')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_jylt='' 或在 config.py 中设置 wy_jylt")sys.exit()except Exception as e:pr("请设置变量 export wy_jylt='' 或在 config.py 中设置 wy_jylt")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()
该脚本为精益论坛自动签到脚本。
主要作用
精益论坛自动签到脚本:使用已登录的
Cookie访问dsu_paulsign:sign插件页,自动识别是否已签到;未签到则提交签到表单,随后抓取个人资料页汇总积分、金币、荣誉、累计/本月/连续签到天数等信息。多账号与通知:从环境变量或
config.py读取wy_jylt(多账号用换行或&分割),逐个执行;每个账号执行完成后通过notify.send("精益论坛", …)推送结果;适合cron定时(示例:20 8 * * *)。
主要方法
pr(message):统一日志收集到全局msg,便于单账号结束一次推送、多账号循环时清空重用。index(cookie)(登录/入口):以
Cookie访问签到插件页面,判断cookie 是否有效与今日是否已签;若已签到,转到主页再次获取用户 uid,直接调用
infoo拉取资料;若未签到,从页面提取 formhash 与 uid/用户名,先
qiandao(formhash, headers),再调用infoo。qiandao(hash, headers)(执行签到):向签到接口提交formhash + qdxq(心情:kx);解析 JSON 返回,输出是否成功与连续签到天数。infoo(id, headers)(资料汇总):进入个人资料页,正则提取积分、金币、荣誉、累计/本月/连续天数并打印汇总。sicxs()(配置与多账号调度):首次运行自动生成
config.py提示;合并环境变量与
config.py的wy_jylt值,按换行或&切分多账号;逐账号调用
index,每个账号结束后发送一次通知并清空msg;最后打印"执行结束"。
使用与注意
必备:抓取并长期有效的论坛
Cookie;一旦<em>登录</em>出现说明失效,需要重新获取。风控:同 IP 多号或异常频率可能触发验证;可在计划任务中错峰或增加随机等待。
鲁棒性:若页面结构/正则字段变动(如
formhash、积分栏位),会出现"解析失败"提示;需更新对应选择器/正则。多账号格式:
export wy_jylt='cookieA\ncookieB'或cookieA&cookieB。依赖:
requests、notify;网络异常未加重试策略,可视需要加超时与重试。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论