某度贴吧签到脚本[本地版,含日志](白嫖实现每日自动签到)
本帖最后由 三滑稽甲苯 于 2020-4-18 21:56 编辑注:由于明天开学,并且连读2周左右,故最近不会回复相关问题。本脚本为我从网上各渠道搜集到的签到脚本的杂交{:301_1001:}
个人使用效果感觉良好{:1_921:}
如果并不需要日志功能,建议前往https://www.52pojie.cn/thread-1155287-1-1.html,本地同样可用。
源码:
from requests import Session
from time import time
start_time = time()
# 数据
log_path = f"E://data/sign_log_{int(start_time)}.txt"#日志记录
like_url = 'https://tieba.baidu.com/mo/q/newmoindex?'
sign_url = 'http://tieba.baidu.com/sign/add'
tbs = '4fb45fea4498360d1547435295'
head = {
'Accept': 'text/html, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Cookie': '填入你的百度cookie(百度一下:如何获取百度cookie)',
'Host': 'tieba.baidu.com',
'Referer': 'http://tieba.baidu.com/i/i/forum',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/71.0.3578.98 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'}
s = Session()
# 获取关注的贴吧
bars = []
dic = s.get(like_url, headers=head).json()['data']['like_forum']
for bar_info in dic:
bars.append(bar_info['forum_name'])
# 签到
already_signed_code = 1101
success_code = 0
need_verify_code = 2150040
already_signed = 0
succees = 0
failed_bar = []
logs = []#日志记录
n = 0
while n < len(bars):
bar = bars
data = {
'ie': 'utf-8',
'kw': bar,
'tbs': tbs
}
try:
r = s.post(sign_url, data=data, headers=head)
except Exception as e:
print(f'未能签到{bar}, 由于{e}。')
failed_bar.append(bar)
continue
dic = r.json()
msg = dic['no']
if msg == already_signed_code: already_signed += 1; r = '已经签到过了!'
elif msg == need_verify_code: n -= 1; r = '需要验证码,即将重试!'
elif msg == success_code: r = f"签到成功!你是第{dic['data']['uinfo']['user_sign_rank']}个签到的吧友,共签到{dic['data']['uinfo']['total_sign_num']}天。"
else: r = '未知错误!' + dic['error']
print(f"{bar}:{r}")
succees += 1
logs.append(dic)#日志记录
n += 1
end_time = time()
t = end_time - start_time
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
print(f'''共{l}个吧,其中: {succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。{failed}
此次运行用时{t}s。''')
with open(log_path,'w') as f:#日志记录
for log in logs:#日志记录
f.write(str(log)+'\n')#日志记录
如果不需要日志则把带“#日志记录”的行删除即可
**签到脚本云函数专用版已出,体验更佳:https://www.52pojie.cn/thread-1155287-1-1.html**
下面是挂到白嫖云服务器上来实现自动签到的方法{:301_997:}
Step1. 注册账号,过程略。网址:https://console.cloud.tencent.com/
Step2. 进入云函数控制台的函数服务:https://console.cloud.tencent.com/scf/index?rid=1
Step3. 单击“新建”
Step4.
Step5.
Step6.
Step7. 测试一下函数运行情况。
如若成功则继续,失败则检查cookie是否过期、填写错误以及网络状况。
Step8. 自动执行
Step9. 洗洗睡,明天早上起来后会发现已经签到了{:301_997:} Simonl 发表于 2020-4-10 10:29
这个可以,我也想自己弄弄一个,但是不知道思路怎么样,楼主能否注释多一点,小白刚开始学
from requests import Session # Session会保持连接,从而加快签到速度
from time import time# 记录始末时间
start_time = time()# 记录开始时间
# 数据
log_path = f"填入保存日志的路径sign_log_{int(start_time)}.txt"# 日志记录路径
like_url = 'https://tieba.baidu.com/mo/q/newmoindex?'# 获取关注的吧列表所用网址
sign_url = 'http://tieba.baidu.com/sign/add'# 签到所用网址
tbs = '4fb45fea4498360d1547435295'
head = {
'Accept': 'text/html, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Cookie': '填入你的百度cookie(百度一下:如何获取百度cookie)',
'Host': 'tieba.baidu.com',
'Referer': 'http://tieba.baidu.com/i/i/forum',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/71.0.3578.98 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'}# 设置请求头及cookie
s = Session()# 创建Session实例
# 获取关注的贴吧
bars = []# 记录关注的贴吧
dic = s.get(like_url, headers=head).json()['data']['like_forum']# 获取关注的吧列表
for bar_info in dic:
bars.append(bar_info['forum_name'])# 过滤信息
# 签到
already_signed_code = 1101# 已经签到返回码
success_code = 0# 签到成功返回码
need_verify_code = 2150040# 需要验证码返回码
already_signed = 0# 记录已经签到的个数
succees = 0# 记录成功签到的个数
failed_bar = []# 记录签到失败的吧
logs = []# 日志记录
n = 0# 循环变量
while n < len(bars):# 主程序
bar = bars
data = {
'ie': 'utf-8',
'kw': bar,
'tbs': tbs
}
try:
r = s.post(sign_url, data=data, headers=head)
except Exception as e:
print(f'未能签到{bar}, 由于{e}。')
failed_bar.append(bar)
continue# 重试
dic = r.json()
msg = dic['no']
if msg == already_signed_code: already_signed += 1; r = '已经签到过了!'
elif msg == need_verify_code: n -= 1; r = '需要验证码,即将重试!'
elif msg == success_code: r = f"签到成功!你是第{dic['data']['uinfo']['user_sign_rank']}个签到的吧友,共签到{dic['data']['uinfo']['total_sign_num']}天。"
else: r = '未知错误!' + dic['error']
print(f"{bar}:{r}")
succees += 1# 签到成功+1
logs.append(dic)#日志记录
n += 1# 循环变量
end_time = time()# 记录结束时间
t = end_time - start_time# 运行时间
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
print(f'''共{l}个吧,其中: {succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。{failed}
此次运行用时{t}s。''')# 报告
with open(log_path,'w') as f:#日志记录
for log in logs:#日志记录
f.write(str(log)+'\n')#日志记录 感谢大神 感谢大神 亲测可用,但是执行完会提示错误,Traceback (most recent call last):
File "C:/Users/admin/Desktop/签到.py", line 71, in <module>
with open(log_path,'w') as f:#日志记录
FileNotFoundError: No such file or directory: 'E://data/sign_log_1586476871.txt' .crx不香么? 代码有了,怎么用啊?!我也想整合一个一键签到 luanshils 发表于 2020-4-10 08:03
亲测可用,但是执行完会提示错误,Traceback (most recent call last):
File "C:/Users/admin/Desktop/ ...
那是因为我添加了日志功能,而你的电脑上没有我习惯放日志的路径。你可以去除或修改此功能:handshake geniusrot 发表于 2020-4-10 08:16
代码有了,怎么用啊?!我也想整合一个一键签到
用python运行
有空我打包成. exe(咕咕咕){:301_997:} 三滑稽甲苯 发表于 2020-4-10 08:19
用python运行
有空我打包成. exe(咕咕咕)
我是用的 idle运行的,因为我是一个py渣渣,只会运行的那种 好的 签到高手一时俱无踪~