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: 25 8 * * *import requestsimport timeimport reimport osimport sysfrom notify import senddef pr(message):msg.append(message+ "\n")print(message)msg = []def index(username, password): # 登录url = "https://gebi1.com/member.php"params = {'mod': "logging",'action': "login",'loginsubmit': "yes",'handlekey': "login",'loginhash': "LGugm",'inajax': "1"}payload = {'referer': "https://gebi1.com/portal.php",'username': username,'password': password,'questionid': "0",'answer': ""}headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.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",'Accept-Encoding': "gzip, deflate, br, zstd",'cache-control': "max-age=0",'origin': "https://gebi1.com",'referer': "https://gebi1.com/portal.php",'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",}# 登录请求response = requests.post(url, params=params, data=payload, headers=headers)if "欢迎您回来" in response.text:pattern = re.compile(r"'username':'(.*?)','usergroup':'(.*?)','uid':'(.*?)','gr")matches = pattern.findall(response.text)if not matches:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returncookies = response.cookiespr(f"登录成功,用户名:{matches[0][0]}")time.sleep(2)sign(matches[0][2],cookies)else:pr("登录失败,请检查账号密码是否正确")sys.exit()def formhash(cookies):url = "https://www.gebi1.cn/forum.php"try:response = requests.get(url, cookies=cookies)info = response.textpattern = re.compile(r'formhash=(.*?)&')matches = pattern.findall(info)if not matches:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnreturn matches[0]except Exception as e:pr(e)def sign(uid,cookies):url = "https://www.gebi1.cn/plugin.php"formhash1 = formhash(cookies)params ={"id": "k_misign:sign","operation": "qiandao","format": "button","formhash": f"{formhash1}","inajax": "1","ajaxtarget": "midaben_sign"}headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0",'referer': "https://www.gebi1.cn/forum.php",'priority': "u=0, i",}try:response = requests.get(url, params=params,headers=headers,cookies=cookies)info = response.textif "今日已签" in info:pr("签到成功")time.sleep(5)my(uid, headers)else:pr("签到失败")except Exception as e:pr(e)def my(uid, headers,cookies):url = f"https://gebi1.com/home.php?mod=space&uid={uid}&do=profile&from=space"try:response = requests.get(url, headers=headers,cookies=cookies)info = response.textpattern = re.compile(r'<span>(.*?)</span>积分</a>')pattern1 = re.compile(r'<span>(.*?)</span>经验值</a>')pattern2 = re.compile(r'<span>(.*?)</span>丝瓜</a>')pattern3 = re.compile(r'<span>(.*?)</span>贡献</a>')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"丝瓜:{matches2[0]},经验:{matches1[0]},贡献:{matches3[0]},积分:{matches[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_gebi")si_cookie = getattr(config, 'wy_gebi', '')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_gebi='' 或在 config.py 中设置 wy_gebi")sys.exit()except Exception as e:pr("请设置变量 export wy_gebi='' 或在 config.py 中设置 wy_gebi")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:list = list_cookie_i.split("#")index(list[0], list[1])except Exception as e:pr(f"执行账号【{i + 1}】时发生错误: {e}")finally:send("隔壁网", ''.join(msg))msg.clear()print(f'\n----------- 执 行 结 束 -----------')if __name__ == '__main__':sicxs()
解析
该脚本为隔壁网自动签到脚本。
主要作用
- 自动登录 + 签到 + 信息查询 + 通知:用账号密码登录 - gebi1.com,获取- uid与会话;到- gebi1.cn取- formhash并调用签到接口;最后到个人主页抓取积分 / 经验值 / 丝瓜 / 贡献并通过- notify.send推送结果。
- 多账号与定时:从环境变量或 - config.py读取多组账号(- username#password,以换行或- &分隔),逐个执行;示例- cron: 25 8 * * *每天 08:25 运行。
主要方法
- pr(message):统一打印并追加到全局- msg,便于最终汇总推送。
- index(username, password):
 向- https://gebi1.com/member.php提交登录表单;解析返回中的- username / usergroup / uid;拿到- cookies后调用- sign(uid, cookies)。
- formhash(cookies):
 访问- https://www.gebi1.cn/forum.php,用正则提取- formhash(签到所需令牌)。
- sign(uid, cookies):
 访问- https://www.gebi1.cn/plugin.php?id=k_misign:sign&operation=qiandao...执行签到;根据返回文本判断"今日已签/签到成功"等,再进入个人信息查询。
- my(uid, headers, cookies):
 访问- https://gebi1.com/home.php?mod=space&uid=...,用正则抓取积分 / 经验值 / 丝瓜 / 贡献并写入日志。
- sicxs()(入口/调度):
 创建或加载- config.py;合并读取- wy_gebi(环境变量与配置文件);解析多账号并循环调用- index();每个账号执行完调用- send("隔壁网", ''.join(msg))推送并清空日志。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
 
没有评论:
发表评论