直接上脚本
脚本临时写的,今天是运行的第一天,虽然报错编码,但是签到、抽奖都成功了。
下面是修改了之后的版本。
# -*- coding: utf-8 -*-
import requests
import logginglogging.basicConfig(level=logging.INFO)def check_sign_in_status(base_url,headers):api = "get_today_status"url = base_url+ apiresponse = requests.get(url, headers=headers)if response.status_code == 200:data = response.json()if data['err_no'] == 0:if data['data'] is True:logging.info("【签到状态】%s","已签到")#print("今天已经签到过了!")return Trueelif data['data'] is False:logging.info("【签到状态】%s","未签到")#print("未签到,可以继续执行签到操作!")return Falseelse:logging.info("【签到状态】%s","未登录,请登录")#print("未登录,请先登录!")passreturn Falseelse:logging.error("【请求失败】%s",response.status_code)#print(f"请求失败,状态码:{response.status_code}")return Falsedef sign_in(base_url,aid,uuid,spider,msToken,a_bogus,headers):api = "check_in"url = base_url+ api + "?aid=" + aid + "&uuid=" + uuid + "&spider=" + spider + "&msToken=" + msToken + "&a_bogus=" + a_bogusresponse = requests.post(url, headers=headers)if response.status_code == 200:try:data = response.json()if data['err_no'] == 0 and data['err_msg'] == "success":logging.info("【签到功能】%s",data['err_msg'])return Falseelse:logging.info("【签到功能】%s",data['err_msg'])except requests.JSONDecodeError:logging.error("【签到功能】服务器返回的数据无法解析为JSON格式。")return Falsedef get_points(base_url,headers):# 这里应该是获取当前积分的逻辑api = "get_cur_point"url = base_url+ apiresponse = requests.get(url, headers=headers)if response.status_code == 200:try:data = response.json()if data['err_no'] == 0 and data['err_msg'] == "success":logging.info("【矿石余额】%s",data['data'])except requests.JSONDecodeError:logging.error("【获取余额功能】服务器返回的数据无法解析为JSON格式。")return Falsedef get_free(base_url,aid,uuid,spider,msToken,a_bogus,headers):#获取免费次数api = "lottery_config/get"url = base_url+ api + "?aid=" + aid + "&uuid=" + uuid + "&spider=" + spider + "&msToken=" + msToken + "&a_bogus=" + a_bogusresponse = requests.get(url, headers=headers)if response.status_code == 200:try:data = response.json()if data['err_no'] == 0 and data['err_msg'] == "success":if data['data']['free_count'] > 0 :# print("免费抽奖次数:",data['data']['free_count'])logging.info("【免费抽奖次数】%s",data['data']['free_count'])return Trueelse:logging.info("【免费抽奖次数】%s",data['data']['free_count'])#print("免费抽奖次数:",data['data']['free_count'])return Falseexcept requests.JSONDecodeError:logging.error("【获取免费抽奖次数功能】服务器返回的数据无法解析为JSON格式。")return Falsedef draw(base_url,aid,uuid,spider,msToken,a_bogus,headers):api = "lottery/draw"url = base_url+ api + "?aid=" + aid + "&uuid=" + uuid + "&spider=" + spider + "&msToken=" + msToken + "&a_bogus=" + a_bogusdata = '{}'response = requests.post(url, headers=headers,data=data)if response.status_code == 200:try:data = response.json()if data['err_no'] == 0 and data['err_msg'] == "success":logging.info("【奖品】%s",data['data']['lottery_name'])#print("奖品:",data['data']['lottery_name'])except requests.JSONDecodeError:logging.error("【抽奖功能】服务器返回的数据无法解析为JSON格式。")return Falsecookie = '你的cookie值'
aid = "你的aid值"
uuid = "你的uuid值"
spider = "你的spider值"
msToken = "你的msToken值"
a_bogus = "你的a_bogus值"
base_url="https://api.juejin.cn/growth_api/v1/"
# 在这里填入实际的headers
header1 = {'Cookie':cookie,'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.61 Chrome/126.0.6478.61 Not/A)Brand/8 Safari/537.36'
}#检查是否签到
if check_sign_in_status(base_url,header1):#已经签到-查看免费抽奖次数-存在则抽奖-最后查询余额if get_free(base_url,aid,uuid,spider,msToken,a_bogus,header1):#抽奖draw(base_url,aid,uuid,spider,msToken,a_bogus,header1)passelse:passget_points(base_url,header1)
else:#未签到-则签到-签完查免费抽奖次数-抽奖-最后查询余额sign_in(base_url,aid,uuid,spider,msToken,a_bogus,header1)if get_free(base_url,aid,uuid,spider,msToken,a_bogus,header1):#抽奖draw(base_url,aid,uuid,spider,msToken,a_bogus,header1)passelse:passget_points(base_url,header1)
脚本中所需要的值都可以登录后的网络请求中获取,其中mstoken和a_bogus的值必须存在,不然页面会返回空值。 aid,uuid在cookie中都有体现。
其中uuid的值为cookie中的user_unique_id
值
效果
然后采用crontab
做个定时任务
效果
我这里直接采用了宝塔执行。