某度贴吧签到脚本[云函数专用版](白嫖实现每日自动签到)
本帖最后由 三滑稽甲苯 于 2021-6-19 14:41 编辑上方是类似的脚本,如若此脚本出错,可试试它们。
V2模拟客户端已出,见https://www.52pojie.cn/thread-1461547-1-1.html。
本脚本为某度贴吧签到脚本(https://www.52pojie.cn/thread-1152714-1-1.html)的云函数版本{:301_1001:}
相较于本地版本,此脚本新添了延时功能以防签到过快,并将代码放置在main函数中以提供入口(不再显示执行错误)
更多新添功能请查看日志。
源码:
# -*- coding: utf8 -*-
from requests import Session
from time import sleep
def main(*args):
# 数据
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':
'BDUSS=你的BDUSS;STOKEN=你的STOKEN',
'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 = []
n = 0
retry_count = 0
max_retry = 5 # 因需要验证码而重试的最大次数
while n < len(bars):
sleep(0.5)
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 and retry_count <max_retry: n -= 1; retry_count += 1; r = f'需要验证码,即将重试!({retry_count}/{max_retry})'
elif msg == need_verify_code: r = '验证码错误,跳过!'; retry_count = 0
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
n += 1
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
message = f'''共{l}个吧,其中{succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。失败列表:{failed}'''
print(message)
s.get(f"https://sc.ftqq.com/你的码.send?text={message}")# [未测试]Server酱推送,不需要则删除此行
retry_count = 0
max_retry = 5 # 因需要验证码而重试的最大次数
while n < len(bars):
sleep(0.5)
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 and retry_count <max_retry: n -= 1; retry_count += 1; r = f'需要验证码,即将重试!({retry_count}/{max_retry})'
elif msg == need_verify_code: r = '验证码错误,跳过!'; retry_count = 0
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
n += 1
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
message = f'''共{l}个吧,其中{succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。失败列表:{failed}'''
print(message) s.get(f"https://sc.ftqq.com/你的SCKEY.send?text={message}")# [未测试]Server酱推送,不需要则删除此行
有了脚本就要挂到白嫖云服务器上来实现自动签到{: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. 自动执行
注意下面Cron表达式中的空格(或者复制:0 0 1 * * * *)
Step9. 洗洗睡,明天早上起来后会发现已经签到了{:301_997:}
Step10. 如若关注贴吧个数过多,请自行修改超时时间(大约为0.7s*关注个数)
日志(2020.4.18日起)
历史版本:https://ww.lanzouj.com/b00zgfori 密码:5dy3
2020
4.18可设置验证码错误的最大尝试次数;server酱推送更加详细;补充了云函数收费的说明。
4.30历史版本
5.16随机休眠几秒
6.14开始研究模拟客户端而非网页签到(遇到难以解决的“目录出错”问题,可能要咕很久)
9.19修改为@弗朗西斯-小明 (https://www.52pojie.cn/?530479)提供的脚本(https://www.52pojie.cn/forum.php ... 155287&pid=31442338)
2021
6.17 感谢支持,高考已结束,开始重构脚本逻辑以及研究模拟客户端签到,成功后由于代码结构有较大改动将开新帖分享
6.18 代码已编写完成,等明天可以再次签到时试试
F&Q(请阅读此栏目后再提问)
1.出现module 'index' has no attribute 'main_handler'
解决方法:仔细查看教程Step5----是不是漏了一步?
2. 出现Task timed out after 3 seconds
解决方法:参照教程Step10.
3. 云函数收费吗?
云函数不收费,但是有流量限制。详情参见:https://cloud.tencent.com/document/product/583/17299
4. 能否做XXX的签到?
没时间,没能力做。
本人仅为贴吧的一个大氵笔,闲暇之余四处搜集信息拼凑成此脚本,并且最近在研究模拟客户端签到,故无精力和时间继续做此类脚本。
5. cookie相关
常见错误:KeyError: 'like_forum'
cookie大致格式为:BDUSS=XXXXX; TOKEN=XXXXXX
获取方法参考http://pandownload.com/faq/cookie.html,将网盘的TOKEN换成贴吧的TOKEN
# 2020.4.16补充:好人一生平安🙏由于pd被封,故无法查看教程,详细步骤可参阅本帖第61楼的方案:https://www.52pojie.cn/forum.php ... 155287&pid=31391633
# 2021.6.17补充:pd官网已可正常访问
由于cookie会过期,所以需要不定时查看签到是否失败,若失败请更换cookie。
神奇的是我的cookie用了几个月都还好用{:301_998:}
正常运行的代码:
# -*- coding: utf8 -*-
from requests import Session
from time import sleep
def main(*args):
# 数据
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':
'BDUSS=你的BDUSS;STOKEN=你的STOKEN',
'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 = []
n = 0
retry_count = 0
max_retry = 5 # 因需要验证码而重试的最大次数
while n < len(bars):
sleep(0.5)
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 and retry_count <max_retry: n -= 1; retry_count += 1; r = f'需要验证码,即将重试!({retry_count}/{max_retry})'
elif msg == need_verify_code: r = '验证码错误,跳过!'; retry_count = 0
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
n += 1
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
message = f'''共{l}个吧,其中{succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。失败列表:{failed}'''
print(message)
s.get(f"https://sc.ftqq.com/你的码.send?text={message}")# [未测试]Server酱推送,不需要则删除此行
retry_count = 0
max_retry = 5 # 因需要验证码而重试的最大次数
while n < len(bars):
sleep(0.5)
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 and retry_count <max_retry: n -= 1; retry_count += 1; r = f'需要验证码,即将重试!({retry_count}/{max_retry})'
elif msg == need_verify_code: r = '验证码错误,跳过!'; retry_count = 0
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
n += 1
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
message = f'''共{l}个吧,其中{succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。失败列表:{failed}'''
print(message)
s.get(f"https://sc.ftqq.com/你的SCKEY.send?text={message}")# [未测试]Server酱推送,不需要则删除此行 补充几点 由于pand*****ad被封 所以Cooike采集办法为 :1.打开贴吧,进入“贴吧个人中心” ;2.按下F12键;3.参考图片操作 (我用的是Chrome浏览器)
https://ftp.bmp.ovh/imgs/2020/04/5092c9c3555ce6e7.jpg
然后将采集到的数据按照:“BDUSS=********************************************
STOKEN=********************************”
粘贴至第14行代码如图:https://ftp.bmp.ovh/imgs/2020/04/8a992fec9dba7fd3.png
至此就可以测试本人亲测有效...{:301_997:} 终于搞好了,谢谢大佬 ,顺便说一句,cooks的正确写法是
'BDUSS=*******************;STOKEN=********************'
61楼的大佬 没加分号,让我弄了半天才搞明白,楼主把这个格式更新到顶楼吧 三滑稽甲苯 发表于 2021-2-10 21:42
@Zeno___Lee
又来一个:https://www.52pojie.cn/thread-1369538-1-1.html
能不能做一个能发帖的功能,比如我有一个签到帖,我想每天自动签到,第**天 签到 这个能实现吗? adsxxhh 发表于 2020-6-6 21:25
请问一下,第五步是不是省略了好几百字呀。
这些知识属于哪个科目呀,我想去学习一下。
emm...
相关的例子看多后就会了{:301_997:}
你可以多多研究有详解的抓包教程{:301_997:}
52论坛有很多的 旗袍妹妹 发表于 2020-4-18 02:43
发现一个问题:普通用户一次只能签到50个吧,当用户关注的吧超过50个之后,从第51个开始,日志重复出现
ht ...
已添加最大尝试次数功能{:1_893:} down_drop 发表于 2020-4-15 12:15
硬是没弄好啊,cookie好像填错了
返回结果
查看教程Step5
将执行方法改为index.main 这是手机客户端和手机网页端的PHP签到代码,楼主能否改造一下,毕竟模拟手机客户端的签到分数比电脑端高几倍
/**
* 50贴吧客户端一键签到
*/
public static function DoSign_Onekey($uid,$kw,$id,$pid,$fid,$ck) {
$ch = new wcurl('http://c.tieba.baidu.com/c/c/forum/msign', array(
'User-Agent: bdtb for Android 6.5.8'
));
$ch->addcookie(array('BDUSS' => $ck));
$temp = array(
'BDUSS' => misc::getCookie($pid),
'_client_id' => '03-00-DA-59-05-00-72-96-06-00-01-00-04-00-4C-43-01-00-34-F4-02-00-BC-25-09-00-4E-36',
'_client_type' => '4',
'_client_version' => '1.2.1.17',
'_phone_imei' => '540b43b59d21b7a4824e1fd31b08e9a6',
'fid' => $fid,
'kw' => $kw,
'net_type' => '3',
'tbs' => misc::getTbs($uid,$ck)
);
self::addTiebaSign($temp);
return $ch->post($temp);
}
/**
* 手机网页签到
*/
public static function DoSign_Mobile($uid,$kw,$id,$pid,$fid,$ck) {
//没问题了
$ch = new wcurl('http://tieba.baidu.com/mo/q/sign?tbs='.misc::getTbs($uid,$ck).'&kw='.urlencode($kw).'&is_like=1&fid='.$fid ,array('User-Agent: fuck phone','Referer: http://tieba.baidu.com/f?kw='.$kw , 'Host: tieba.baidu.com','X-Forwarded-For: 115.28.1.'.mt_rand(1,255), 'Origin: http://tieba.baidu.com', 'Connection: Keep-Alive'));
$ch->addcookie(array('BDUSS' => $ck,'BAIDUID' => strtoupper(md5(time()))));
return $ch->exec();
}
/**
* 网页签到
*/ 好东西啊,可惜我今天评分已经没有了{:301_997:} WuBuShanYan 发表于 2020-4-13 13:27
好东西啊,可惜我今天评分已经没有了
明天成功后来评分也不错啊{:301_1001:} 去试试在回来评论~~ 之前也写过类似的扔到服务器上楼主所见略同啊 楼主百度cookie 是BDUSS?
是直接那一长串的还是要加头 本帖最后由 大手笔 于 2020-4-13 14:11 编辑
<img style="width:50%;height:50%" src="https://attach.52pojie.cn//forum/202004/13/135453vnpf7azxzd7qmngq.jpg?">
Cookie格式是这样吗 百度贴吧等级高有什么用
厉害!想问一下这个云函数收费吗?:lol 太高深,不懂!!