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: 0 8 * * *"""import requestsimport re,os,sysimport timeimport randomfrom notify import senddef pr(message):msg.append(message + "\n" )print(message)msg = []def index(cookie): #登录url = 'https://hostloc.com/forum.php'header = {"authority": "hostloc.com","method": "GET","path": "/forum.php","scheme": "https","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","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","referer": "https://hostloc.com/","cookie":cookie}try:response = requests.get(url=url,headers=header )if "积分" in response.text:pr("登陆成功")pattern = re.compile(r"discuz_uid = '(.*?)'")matches = pattern.findall(response.text)if not matches:pr("解析用户信息失败,可能页面结构变化或 cookie 无效")returnuid = str(matches[0])sicxs_task(cookie)time.sleep(5)my(cookie,uid)else:pr("登录失败")except Exception as e:pr(e)def my(cookie,uid): #我的信息url = f'https://hostloc.com/home.php?mod=space&uid={uid}&do=profile'header = {"Connection":"keep-alive","authority":"hostloc.com","method":"GET","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","referer":"https://hostloc.com/","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 Edg/130.0.0.0","content-type": "text/html; charset=utf-8","cookie":cookie}response = requests.get(url=url,headers=header)pattern = re.compile(r'title="访问我的空间">(.*?)</a>')pattern2 = re.compile(r'<li><em>积分</em>(.*?)</li><li><em>威望</em>(.*?) </li>')pattern3 = re.compile(r'<li><em>金钱</em>(.*?) </li>')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][0] + " 威望:" + matches1[0][1] + " 金钱:" + matches2[0])def sicxs_task(cookie):#任务for i in range(10):uuid = random.randint(5000, 15000)time.sleep(5)url = f'https://hostloc.com/space-uid-{uuid}.html'header = {"Connection":"keep-alive","authority":"hostloc.com","method":"GET","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","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 Edg/130.0.0.0","content-type": "text/html; charset=utf-8","cookie":cookie}response = requests.get(url=url,headers=header)info = response.textif "个人资料"in info:pr(f"第{i}次访问{uuid}用户成功")elif "您指定的用户空间不存在" in info:pr("访问失败,重试中")else: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_hostloc")si_cookie = getattr(config, 'wy_hostloc', '')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_hostloc='' 或在 config.py 中设置 wy_hostloc")sys.exit()except Exception as e:pr("请设置变量 export wy_hostloc='' 或在 config.py 中设置 wy_hostloc")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()
解析
该脚本为全球主机论坛自动赚积分脚本。
主要作用
全球主机论坛(hostloc.com)自动任务脚本:用
cookie模拟登录,执行"随机访问用户空间"的日常任务以获取积分增量,随后抓取并汇总账号信息(用户名、积分、威望、金钱)。多账号与通知:从环境变量或
config.py读取多个账号(以换行或&分割),逐个执行,最后通过notify.send("全球主机论坛", …)推送结果,便于定时(cron: 0 8 * * *)运行。
主要方法
pr(message): 统一日志收集与打印(写入全局msg,最终用于通知汇总)。index(cookie):GET /forum.php校验登录(页面包含"积分"视为成功);用正则
discuz_uid = '...'提取uid;先执行
sicxs_task(cookie)(日常任务),等待 5 秒后调用my(cookie, uid)查询资料。sicxs_task(cookie): 随机生成 10 个uid(5000–15000),依次访问https://hostloc.com/space-uid-<uid>.html,若页面含"个人资料"则判定访问成功;用于触发站内"访问空间得积分"的日常加分。my(cookie, uid):GET /home.php?mod=space&uid=<uid>&do=profile,通过正则提取用户名、积分、威望、金钱并输出。sicxs():初始化/创建
config.py;合并读取
wy_hostloc(环境变量与config.py同名变量),按**换行或&**切分多账号;逐个账号执行
index();每个账号结束后发送一次通知并清空msg;最后打印"执行结束"。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论