python新人,远景论坛签到脚本
本帖最后由 yuanxinjie 于 2024-5-24 14:20 编辑去年学测试,顺带学了点python,找不到工作闲着没事写点脚本练手
我自己挂到青龙运行个把月了
更新一下:
完善接入青龙面板,cookie值换用环境变量方式添加,添加青龙通知推送接口,代码已在仓库更新
仓库地址:iXinjie/qlScripts (github.com)
个别账号回复帖子需要验证码的情况我还解决不了,就只能实现自动打卡,将回复帖子的执行函数删掉即可
需要填一下里面的Cookie,格式就是下图这样
https://s2.xptou.com/2023/04/22/64436fd43ab30.png
就是saltkey和auth这两个值,自己去抓一下,前缀不知道每个账号是不是一样的
https://s2.xptou.com/2023/04/22/64436fd49e274.png
我也只会点基础用法,还请大家指点
"""
cron: 0 0 8 ? * *
new Env('远景论坛签到');
"""
import requests
from datetime import datetime
import time
import re
import html
cookies = "jqCP_887f_saltkey=; jqCP_887f_auth="
# 回帖内容
replyMsg = "回帖签到"
pcUrl = "https://i.pcbeta.com/home.php?mod=task&do=apply&id=149"
pcHeaders = {
"Host": "i.pcbeta.com",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Cookie": cookies
}
pcbbsHeaders = {
"Host": "bbs.pcbeta.com",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Cookie": cookies
}
# 领取奖励链接
lqurl = "https://i.pcbeta.com/home.php?mod=task&do=draw&id="
# 获取新任务链接
newUrl = "https://i.pcbeta.com/home.php?mod=task&item=new"
# 获取进行中的任务链接
doingUrl = "https://i.pcbeta.com/home.php?mod=task&item=doing"
# 查看已完成任务链接
doneUrl = "https://i.pcbeta.com/home.php?mod=task&item=done"
# 获取签到状态信息
newTaskRes = requests.get(url=newUrl,headers=pcHeaders).text
doingTaskRes = requests.get(url=doingUrl,headers=pcHeaders).text
doneTaskRes = requests.get(url=doneUrl, headers=pcHeaders).text
doingRes = requests.get("https://i.pcbeta.com/home.php?mod=task&item=doing",headers=pcHeaders)
def convert_text(text):
return ''.join()
def writeLog(file):
time = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
with open(f"./log/pcBetalog-{time}.html", "w") as f:
f.write(file)
def pcbetaCheckin():
import time
id = "149"
if "每日打卡" in newTaskRes:
# 开始执行签到
taskRes = requests.get(url=pcUrl, headers=pcHeaders).text
if "抱歉,本期您已申请过此任务,请下期再来" in taskRes:
return "已签到,请勿重复签到"
elif "恭喜您,任务已成功完成" in taskRes:
return "签到成功"
else:
time.sleep(1)
lqRes = requests.get(url=lqurl+id, headers=pcHeaders).text
if "任务已成功完成" in lqRes:
return "签到成功,PB币+1"
if "不是进行中的任务" in lqRes:
# 检查是否签到成功
doneTaskRes_check = requests.get(url=doneUrl, headers=pcHeaders).text
if "每日打卡" in doneTaskRes_check:
return "签到已完成"
else:
return "签到失败"
else:
writeLog(lqRes)
return "签到失败,具体情况请查看日志"
elif "每日打卡" in doneTaskRes:
return "今日已签到,重复签到"
def getTaskUrl():
global idd
idd = getTaskID()
# 获取任务贴URL
viewRes = requests.get(url=f"https://i.pcbeta.com/home.php?mod=task&do=view&id={idd}", headers=pcHeaders)
tieUrl = re.search(r'在“<a href="(.+?)">', viewRes.text).group(1)
replyRes = requests.get(url=tieUrl,headers=pcbbsHeaders)
# 获取fid
fid = re.search(r'fid=(.+?)&', replyRes.text).group(1)
# 获取tid
tid = re.search(r'tid=(.+?)&', replyRes.text).group(1)
formhash = re.search(r'formhash=(.+?)&', replyRes.text).group(1)
replyUrl = f"https://bbs.pcbeta.com/forum.php?mod=post&action=reply&fid={fid}&tid={tid}&extra=page=1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1"
return replyUrl,formhash
def getTaskID():
news = requests.get(url=newUrl,headers=pcHeaders).text
doing = requests.get(url=doingUrl,headers=pcHeaders).text
if "回帖打卡" in news:
idd = re.search('id=(.+?)">回帖打卡', news).group(1)
return idd
elif "回帖打卡" in doing:
idd = re.search('id=(.+?)">回帖打卡', doing).group(1)
return idd
else:
return False
def pcbetaReply():
taskName = "回帖打卡福利"
if taskName in newTaskRes:
# 获取任务id
global idd
idd = getTaskID()
# 申请回帖打卡任务
reRes = requests.get(url=f"https://i.pcbeta.com/home.php?mod=task&do=apply&id={idd}", headers=pcHeaders)
if "任务申请成功" in reRes.text:
result = getTaskUrl()
# 回复帖子
data = {"message": convert_text(replyMsg),
"posttime":int(time.time()),
"formhash": result,
"subject":"",
"usesig":"1"}
resRes = requests.post(url=result, headers=pcbbsHeaders, data=data)
if "回复发布成功" in resRes.text:
# 领取奖励
lqRes1 = requests.get(url=lqurl+idd,headers=pcHeaders)
# 获取任务状态
doneTaskRes1 = requests.get(url=doneUrl, headers=pcHeaders)
if taskName in doneTaskRes1.text:
return "打卡成功,PB币+2"
else:
writeLog(lqRes1.text)
return "奖励领取失败"
else:
writeLog(resRes.text)
return "回帖失败"
else:
writeLog(reRes.text)
return "打卡任务申请失败"
elif taskName in doneTaskRes:
return "打卡已完成,重复打卡"
elif taskName in doingRes.text:
result = getTaskUrl()
# 回复帖子
data = {"message":replyMsg,
"posttime":int(time.time()),
"formhash": result,
"subject":"",
"usesig":"1"}
resRes = requests.post(url=result, headers=pcbbsHeaders, data=data)
if "回复发布成功" in resRes.text:
# 领取奖励
lqRes1 = requests.get(url=lqurl+idd, headers=pcHeaders)
# 获取任务状态
doneTaskRes1 = requests.get(url=doneUrl, headers=pcHeaders)
if taskName in doneTaskRes1.text:
return "打卡成功,PB币+2"
else:
writeLog(lqRes1.text)
return "奖励领取失败"
else:
writeLog(resRes.text)
return "回帖失败"
else:
return "没有此任务"
if __name__ == "__main__":
print(pcbetaCheckin())
print(pcbetaReply())如有违规请管理删帖 赵天源 发表于 2024-7-22 10:06
填了也不好使,青龙不是有个变量嘛,里面填了,还是这个错误
我以为是你脚本更新,把变量改了,我把脚本 ...
这个脚本没有变量,是直接在脚本里面修改cookie的,你把你的cookie贴出来我看看 yuanxinjie 发表于 2024-5-19 14:20
你把你错误的代码全部贴出来看看,我这直接复制运行是没问题的
日志里面的内容
## 开始执行... 2024-05-20 12:59:00
File "/ql/data/scripts/pcbeta.py", line 5
"""
^
SyntaxError: unterminated triple-quoted string literal (detected at line 162)
## 执行结束... 2024-05-20 12:59:01耗时 1 秒 这个论坛居然还活着,之前装系统都是在上面找镜像 cy465728759 发表于 2023-4-22 15:54
这个论坛居然还活着,之前装系统都是在上面找镜像
我当初进着论坛是为了找黑苹果方面的东西,现在不玩黑果也没啥好看的了 缺的是注册邀请码。{:1_923:} 缺的是注册邀请码。百度贴吧水道8级了 shandian281 发表于 2023-4-22 16:31
缺的是注册邀请码。
我当初好像是tb几块钱买的邀请码,也不贵,现在应该还有 学习了,有用 yuanxinjie 发表于 2023-4-22 16:46
我当初好像是tb几块钱买的邀请码,也不贵,现在应该还有
我去看看。:lol F12找的,没找到jqCP_887f_saltkey与jqCP_887f_auth= 感谢分享
这样就不用费手指了:lol