iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >利用python+crontab定时任务,实现ikuuu账户(vpn)自动签到
  • 952
分享到

利用python+crontab定时任务,实现ikuuu账户(vpn)自动签到

python开发语言自动化机器人linux 2023-10-06 09:10:08 952人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

目录 一、思路二、实现1、python脚本2、crontab任务 一、思路 创建python脚本,调用对应https接口,实现登录、签到功能; 2、创建crontab定时任务,定时执行

目录

一、思路

创建python脚本,调用对应https接口,实现登录、签到功能;
2、创建crontab定时任务,定时执行Python签到脚本。

二、实现

1、python脚本

创建一个脚本ikuuuCheckIn.py,内容为:

#!/usr/bin/python#coding=UTF-8__author__ = 'huangsan'import requestsimport datetime#修改默认encoding方式,解决Python中的UnicodeEncodeError编码错误问题import sysreload (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 += 1def 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()

2、crontab任务

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分执行一次,执行输出日志追加至对应文件。

来源地址:https://blog.csdn.net/weixin_44005802/article/details/132062277

--结束END--

本文标题: 利用python+crontab定时任务,实现ikuuu账户(vpn)自动签到

本文链接: https://www.lsjlt.com/news/424026.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作