赞
踩
1、创建python脚本,调用对应https接口,实现登录、签到功能;
2、创建crontab定时任务,定时执行python签到脚本。
创建一个脚本ikuuuCheckIn.py,内容为:
#!/usr/bin/python #coding=UTF-8 __author__ = 'huangsan' import requests import datetime #修改默认encoding方式,解决Python中的UnicodeEncodeError编码错误问题 import sys reload (sys) sys.setdefaultencoding('utf-8') def main(): #打印当前时间 print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) # 需要签到的账号 accountList = ['userName@163.com&userPwd'] print("共需要签到" + str(len(accountList)) + "个账号") i = 1 for account in accountList: print("=====正在执行第" + str(i) + "个账号=====") email = account.split('&')[0] passwd = account.split('&')[1] sign_in(email, passwd) print("=====第" + str(i) + "个账号,执行完毕=====") i += 1 def sign_in(email, passwd): # 请求头 headers = {'Accept':'application/json, text/javascript, */*; q=0.01','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8','user-agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'} # 请求参数 body = {"email" : email,"passwd" : passwd,} # session httpSession = requests.session() try: # 登录 print("登录") loginResp = httpSession.post('https://ikuuu.art/auth/login', headers=headers, data=body) print("loginResp=" + loginResp.text.decode("unicode_escape")) if 1 != loginResp.json()['ret'] : print("登录失败,请检查帐号配置是否错误:email=" + email + ", passwd=" + passwd) return except Exception as e: # 登录异常,记录信息 raise Exception("登录异常:email=" + str(email) + ", passwd=" + passwd + ", e:" + repr(e)) print("登录成功") try: # 签到 print("签到") checkinResp = httpSession.post('https://ikuuu.art/user/checkin') print("checkinResp=" + checkinResp.text.decode("unicode_escape")) if 1 != checkinResp.json()['ret'] : print("签到失败:email=" + email + ", passwd=" + passwd) return except Exception as e: # 签到异常,记录信息 print("签到异常:email=" + email + ", passwd=" + passwd + ", e:" + repr(e)) print("签到成功") # 入口 if __name__ == '__main__': main()
以Linux为例:
通过crontab -l可查看当前所有定时任务。
通过crontab -e可添加新的定时任务:
30 0 * * * /root/temp/pyTest/ikuuuCheckIn.py >> /root/temp/pyTest/ikuuuCheckIn.log_u_$(date -u +"\%Y\%m").log 2>&1
每天0点30分执行一次,执行输出日志追加至对应文件。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。