本脚本为某度贴吧签到脚本(/thread-1152714-1-1.html)的云函数版本
相较于本地版本,此脚本新添了延时功能以防签到过快,并将代码放置在main函数中以提供入口(不再显示执行错误)
Python
# -*- coding: utf8 -*-
from requests import Session
from time import sleep
def main(*args):
# 数据
like_url = '/mo/q/newmoindex?'
sign_url = '/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(获取方法参考/faq/cookie.html,将网盘的TOKEN换成贴吧的TOKEN',
'Host': '',
'Referer': '/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
while n < len(bars):
sleep(0.5)
bar = bars[n]
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
n += 1
l = len(bars)
failed = "\n失败列表:"+'\n'.join(failed_bar) if len(failed_bar) else ''
print(f'''共{l}个吧,其中: {succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。{failed}''')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64# -*- coding: utf8 -*-
fromrequestsimportSession
fromtimeimportsleep
defmain(*args):
# 数据
like_url='/mo/q/newmoindex?'
sign_url='/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(获取方法参考/faq/cookie.html,将网盘的TOKEN换成贴吧的TOKEN',
'Host':'',
'Referer':'/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']
forbar_infoindic:
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
whilen
sleep(0.5)
bar=bars[n]
data={
'ie':'utf-8',
'kw':bar,
'tbs':tbs
}
try:
r=s.post(sign_url,data=data,headers=head)
exceptExceptionase:
print(f'未能签到{bar}, 由于{e}。')
failed_bar.append(bar)
continue
dic=r.json()
msg=dic['no']
ifmsg==already_signed_code:already_signed+=1;r='已经签到过了!'
elifmsg==need_verify_code:n-=1;r='需要验证码,即将重试!'
elifmsg==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)iflen(failed_bar)else''
print(f'''共{l}个吧,其中: {succees}个吧签到成功,{len(failed_bar)}个吧签到失败,{already_signed}个吧已经签到。{failed}''')
如果不需要日志则把带“#日志记录”的行删除即可
有了脚本就要挂到白嫖云服务器上来实现自动签到
Step1. 注册账号,过程略。网址:https://console./
Step2. 进入云函数控制台的函数服务:https://console./scf/index?rid=1
Step3. 单击“新建”
Step4.
Step5.
Step6.
Step7. 测试一下函数运行情况。如若成功则应该能看到“测试成功”,输出与图示相似;失败则检查cookie是否过期、填写错误以及网络状况。
Step8. 自动执行
注意下面Cron表达式中的空格(或者复制:0 0 1 * * * *)
Step9. 洗洗睡,明天早上起来后会发现已经签到了
Step10. 如若关注贴吧个数过多,请自行修改超时时间(大约为0.7s*关注个数)
python百度贴吧发帖签到_【Python】某度贴吧签到脚本[云函数专用版](白嫖实现每日自动签到)...