全球某工商云战役自动打卡系统


前言

考试周不想复习,自学python,看了一个下午毫无感觉,于是想着实操一下,试试能不能搞个云战役自动打卡,搞到凌晨两点左右成功实现了使用python批量打卡,后来不断改进增加功能,大致实现了用户的添加每日自动批量打卡以及每日打卡成功之后的信息报送,不过仍有很多不足的地方还需改进


一、python连接打卡网站实现自动批量打卡

1.代码

代码如下(示例):

import requests
import time
url='https://nco.zjgsu.edu.cn/genqrcode/2019032'
file = open("C:/Users/Administrator/Desktop/python文件/spide/helloSpide.txt", "r")
file_read = file.readlines()#读取文件内容(以列表形式)
lenthOfFile = len(file_read)#确定长度
for i in range(0, lenthOfFile, 4):#这里是4后边增加了邮箱信息之后会变成5
    # 每一个for循环签到一次
    file_read_name = file_read[i]#读取用户名(学号)
    file_read_name = file_read_name.strip()#将读取的用户名去空格及回车
    file_read_pass = file_read[i+1]#读取密码
    file_read_pass = file_read_pass.strip()
    file_read_first_location = file_read[i+2]#读取省市
    file_read_first_location = file_read_first_location.strip()
    file_read_last_location = file_read[i+3]#读取地区
    file_read_last_location = file_read_last_location.strip()
    # 读取文件内容并存储
    # 以下是第一个界面
    myHeaders_1 = {
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '#页面只允许手机端访问于是更改头部为手机可以直接网上搜代理(这一步很关键)
    }
    url = 'https://nco.zjgsu.edu.cn/genqrcode/2019032'
    r3 = requests.post(url, headers=myHeaders_1)  # 向https://nco.zjgsu.edu.cn/genqrcode/2019032发送请求(进入登录界面)

    yourLocal1 = file_read_first_location  # 读取现在地址的首地址(例如浙江省杭州市)
    yourLocal2 = file_read_last_location  # 读取具体地址
    myHeaders_2 = {
        'Upgrade-Insecure-Requests': '1',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': 'zjgsusessionsid=s%3AGSYaaVwF_2pedsizsHYTYSY64hVl3vL_.NMnLf1bV1PJSAS%2FeZXUkcyPkFpBq%2BcMVQYq4XPHXAAU; _ncov_uuid=a59e0ac8-da06-4fb1-83d8-000976c317a9; _ncov_username=1910080117; _ncov_psswd=09187X',
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '
        
    }
    myHeaders_2['Cookie'] = r3.headers['set-cookie']#将获得的cookie传到下一个文件头(进行cookie的替换)
    payload = {
        'name': ' ', 'psswd': ' '
    }
    payload['name'] = file_read_name#设置post参数
    payload['psswd'] = file_read_pass#设置post参数
    url = 'https://nco.zjgsu.edu.cn/login'
    r=requests.post(url, data=payload, headers=myHeaders_2)#登录
    # r.encoding='utf-8'
    print(r.text)
    print(r.headers)
    time.sleep(10)  # 界面跳转休息十秒怕被抓

    myHeaders_3 = {
        'Upgrade-Insecure-Requests': '1',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': 'zjgsusessionsid=s%3AOIlBmUda3tnT-fWds6uWEKKADgTt3IAd.zQ1LcseRzDNFPv5EU1AlkyyWeSMz6424x6HK8cbov8Q; _ncov_uuid=03d31c9b-696f-4429-a0ca-6e2b7a2e10ce; _ncov_username=1910080117; _ncov_psswd=09187X',
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '
        
    }
    myHeaders_3['Cookie'] = r.headers['set-cookie']#传递cookie
    payload2 = {
        'uuid': 'a59e0ac8-da06-4fb1-83d8-000976c317a9',
        'locationInfo': '%E6%B5%99%E6%B1%9F%E7%9C%81%E6%9D%AD%E5%B7%9E%E5%B8%82',
        'currentResd': '%E6%B5%99%E6%B1%9F%E7%9C%81%E6%B8%A9%E5%B7%9E%E5%B8%82%E9%BE%99%E6%B8%AF%E5%B8%82%E4%B8%B4%E6%B8%AF%E8%B7%AF862%E5%8F%B7',
        'fromHbToZjDate': '',
        'fromHbToZj': 'C',
        'fromWtToHzDate': '',
        'fromWtToHz': 'B',
        'meetDate': '',
        'meetCase': 'C',
        'travelDate': '',
        'travelCase': 'D',
        'medObsvReason': '',
        'medObsv': 'B',
        'belowCaseDesc': '',
        'belowCase': 'D',
        'temperature': '',
        'notApplyReason': '',
        'hzQRCode': 'A',
        'specialDesc': ''
    }
    payload2['locationInfo'] = yourLocal1  # 换地址
    payload2['currentResd'] = yourLocal2  # 换地址
    url2 = 'https://nco.zjgsu.edu.cn/'
    r2 = requests.post(url2, data=payload2, headers=myHeaders_2)#打卡成功
    # r.encoding='utf-8'
    print(r2.text)
    time.sleep(5)  # 完成一个人的休眠五秒然后继续打卡下一个人
    

2.关键部分分析

代码如下(示例):

 r=requests.post(url, data=payload, headers=myHeaders_2)

前面的代码都是围绕着这一部分代码展开的,构造url也号payload也好headers也好,只要构造得当便可实现想要的功能
例如:
前面只能用手机端登录打卡界面,于是将headers中的user-agent更改为安卓端的user-agent便可

myHeaders_1['User-Agent'] = 'xxxxxxxx'

二、定时启动打卡程序

1、腾讯服务器

显然我的电脑不能一直开着,所以和室友花重金(可怜学生党)买了腾讯服务器。
腾讯云云服务器 (Cloud Virtual Machine,CVM) 是在云中提供可扩展的计算服务。 [1] 腾讯云在亚太云计算市场份额位列第四,首次超过谷歌。

2、使用linux+crontab添加定时启动项

忘记crontab是不是自带的了,如果要安装

yum install vixie-cron
yum install crontabs

之后添加定时启动项,不过在这之前要先熟悉一下crontab的使用
打开crontab

crontab -e

这时会进入vi编辑器模式,然后在新的一行添加你你想要的定时任务,不过这要熟悉cron表达式的语法例如每天0点启动

0 0 * * * 程序名 >>想记录的日志名

我crontab里面的内容:

2 0 * * * python /root/ShareFile/myFirstSpide.py >>/root/ShareFile/EverDay.txt

代表着每天0:02使用python打开myFirstSpide.py并将运行记录写入EverDay.txt

三、每日报送成功发送邮件

1、发送邮件功能

这里是利用smtp来发送,使用smtp时需要在你的邮箱设置里开启此功能,并获得动态密码

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# from email.mime.image import MIMEImage
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com', 25)#这里使用163来发送邮件qq的话改为smtp.qq.com
username = 'xxxxxxxx'#你的邮箱名
password = 'xxxxxxxx'#你的动态密码(注意这里不是你的密码而是你在163开启的smtp的动态码)
smtp.login(username, password)
sender = 'xxxxxxx'#发送人邮箱名
receiver = 'xxxxxxx'#接收者邮箱
#发送邮件文本内容
subject = 'pythonmailtest'#文件内容
msg = MIMEMultipart('mixed') 
msg['Subject'] = subject
msg['From'] = 'xxxxxx@163.com <xxxxxx@163.com>'
msg['To'] = 'xxxxxxxx@qq.com'
text = 'Hello World'#文件内容
text_plain = MIMEText(text, 'plain', 'utf-8')#邮件内容
msg.attach(text_plain)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

2、结合打卡,完成每日打卡成功通知

import requests
import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
url='https://nco.zjgsu.edu.cn/genqrcode/2019032'

#发送邮件程序
def sentSecessMsg(receiver):
    smtp = smtplib.SMTP()
    smtp.connect('smtp.qq.com', 25)
    username = 'xxxxxxx'
    password = 'xxxxxxx'
    smtp.login(username, password)
    sender = 'xxxxxxx'
    #发送邮件文本内容
    subject = '哈喽哈:今日报送成功'
    msg = MIMEMultipart('mixed') 
    msg['Subject'] = subject
    msg['From'] = 'xxxxxxx@qq.com <xxxxxx@qq.com>'
    msg['To'] = receiver
    text = '打卡成功'
    text_plain = MIMEText(text, 'plain', 'utf-8')
    msg.attach(text_plain)
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()


file = open("C:/Users/Administrator/Desktop/python文件/spide/helloSpide.txt", "r")
file_read = file.readlines()
lenthOfFile = len(file_read)
for i in range(0, lenthOfFile, 5):
    # 每一个for循环签到一次
    file_read_name = file_read[i]
    file_read_name = file_read_name.strip()
    file_read_pass = file_read[i+1]
    file_read_pass = file_read_pass.strip()
    file_read_first_location = file_read[i+2]
    file_read_first_location = file_read_first_location.strip()
    file_read_last_location = file_read[i+3]
    file_read_last_location = file_read_last_location.strip()
    # 读取文件内容并存储
    # 以下是第一个界面
    myHeaders_1 = {
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '#页面只允许手机端访问于是更改头部为手机
    }
    url = 'https://nco.zjgsu.edu.cn/genqrcode/2019032'
    r3 = requests.post(url, headers=myHeaders_1)  # 向https://nco.zjgsu.edu.cn/genqrcode/2019032发送请求

    yourLocal1 = file_read_first_location  # 读取现在地址的首地址(例如浙江省杭州市)
    yourLocal2 = file_read_last_location  # 读取具体地址
    myHeaders_2 = {
        'Upgrade-Insecure-Requests': '1',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': 'zjgsusessionsid=s%3AGSYaaVwF_2pedsizsHYTYSY64hVl3vL_.NMnLf1bV1PJSAS%2FeZXUkcyPkFpBq%2BcMVQYq4XPHXAAU; _ncov_uuid=a59e0ac8-da06-4fb1-83d8-000976c317a9; _ncov_username=1910080117; _ncov_psswd=09187X',
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '
        
    }
    myHeaders_2['Cookie'] = r3.headers['set-cookie']#将获得的cookie传到下一个文件头
    payload = {
        'name': ' ', 'psswd': ' '
    }
    payload['name'] = file_read_name
    payload['psswd'] = file_read_pass
    url = 'https://nco.zjgsu.edu.cn/login'
    r=requests.post(url, data=payload, headers=myHeaders_2)
    # r.encoding='utf-8'
    print(r.text)
    print(r.headers)
    # print(r.headers['Url-Hash'])
    # https://blog.csdn.net/sinat_32258909/article/details/52404305
    time.sleep(10)  # 界面跳转休息十秒

    myHeaders_3 = {
        'Upgrade-Insecure-Requests': '1',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': 'zjgsusessionsid=s%3AOIlBmUda3tnT-fWds6uWEKKADgTt3IAd.zQ1LcseRzDNFPv5EU1AlkyyWeSMz6424x6HK8cbov8Q; _ncov_uuid=03d31c9b-696f-4429-a0ca-6e2b7a2e10ce; _ncov_username=1910080117; _ncov_psswd=09187X',
        'User-Agent': 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02 '
        
    }
    myHeaders_3['Cookie'] = r.headers['set-cookie']
    payload2 = {
        'uuid': 'a59e0ac8-da06-4fb1-83d8-000976c317a9',
        'locationInfo': '%E6%B5%99%E6%B1%9F%E7%9C%81%E6%9D%AD%E5%B7%9E%E5%B8%82',
        'currentResd': '%E6%B5%99%E6%B1%9F%E7%9C%81%E6%B8%A9%E5%B7%9E%E5%B8%82%E9%BE%99%E6%B8%AF%E5%B8%82%E4%B8%B4%E6%B8%AF%E8%B7%AF862%E5%8F%B7',
        'fromHbToZjDate': '',
        'fromHbToZj': 'C',
        'fromWtToHzDate': '',
        'fromWtToHz': 'B',
        'meetDate': '',
        'meetCase': 'C',
        'travelDate': '',
        'travelCase': 'D',
        'medObsvReason': '',
        'medObsv': 'B',
        'belowCaseDesc': '',
        'belowCase': 'D',
        'temperature': '',
        'notApplyReason': '',
        'hzQRCode': 'A',
        'specialDesc': ''
    }
    payload2['locationInfo'] = yourLocal1  # 换地址
    payload2['currentResd'] = yourLocal2  # 换地址
    url2 = 'https://nco.zjgsu.edu.cn/'
    r2 = requests.post(url2, data=payload2, headers=myHeaders_2)
    # r.encoding='utf-8'
    print(r2.text)
    time.sleep(5)  # 完成一个人的休眠五秒然后继续打卡下一个人
    # 读取邮箱地址
    MailAddress = file_read[i+4]
    MailAddress = MailAddress.strip()
    sentSecessMsg(MailAddress)
    

三、图形化界面的设计

这里就不多说了,自己慢慢画

import tkinter as tk
import tkinter.messagebox
from PIL import Image
from PIL import ImageTk
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import os
#创建窗口
window = tk.Tk()
window.title("自动打卡小程序")  #窗口标题
window.geometry('500x300')  #尺寸
#添加背景

# photo = tk.PhotoImage(file='C:/Users/Administrator/Desktop/python文件/spide/1.png')
# thePhotoLabel = tk.Label(window, image=photo,compound=tk.CENTER)
# thePhotoLabel.pack()
# def writeToText():
#     myFile=open("C:/Users/Administrator/Desktop/python文件/spide/helloSpide.txt",)

# def get_image(filename,width,height):
#     im = Image.open(filename).resize((width,height))
#     return ImageTk.PhotoImage(im)
# #添加图片
# Dpath = os.path.abspath('.')
# canvas_root = tkinter.Canvas(window, width=500,height=300)
# im_root = get_image(Dpath+'\\picture\\k.png', 800,600)
# canvas_root.create_image(400,300, image=im_root)
# canvas_root.pack()

tk.Label(window, text='用户名:', font=('微软雅黑', 14)).place(x=90, y=20)
tk.Label(window, text='密   码:', font=('微软雅黑', 14)).place(x=90, y=60)
tk.Label(window, text='居住省市:', font=('微软雅黑', 14)).place(x=70, y=100)
tk.Label(window, text='居住地:', font=('微软雅黑', 14)).place(x=90, y=140)
tk.Label(window, text='邮   箱:', font=('微软雅黑', 14)).place(x=90, y=180)

userNameEntry = tk.Entry(window)
userPasswordEntry = tk.Entry(window, show='*')
userNameEntry.place(x=170, y=25)
userPasswordEntry.place(x=170, y=65)

userFirstAddress = tk.Entry(window)
userLastAddress = tk.Entry(window)
userFirstAddress.place(x=170, y=105)
userLastAddress.place(x=170, y=145)

EmailAddress = tk.Entry(window)
EmailAddress.place(x=170, y=185)



def writeInText():
    # myFile = open('C:/Users/Administrator/Desktop/python文件/spide/helloSpide.txt', 'a+')
    # myFile.write('\n'+userNameEntry.get()+'\n')
    # myFile.write(userPasswordEntry.get()+'\n')
    # myFile.write(userFirstAddress.get()+'\n')
    # myFile.write(userLastAddress.get())
    # myFile.close()
    if userNameEntry.get()=='' or userPasswordEntry.get()=='' or userFirstAddress.get()=='' or userLastAddress.get()=='' or EmailAddress.get()=='':
        tkinter.messagebox.showinfo(title='提示', message='输入框不能为空')
    else:
        AllInfo = userNameEntry.get()+'\n'+userPasswordEntry.get()+'\n'+userFirstAddress.get()+'\n'+userLastAddress.get()+'\n'+EmailAddress.get()
        smtp = smtplib.SMTP()
        smtp.connect('smtp.qq.com', 25)
        username = 'xxxxx@qq.com'
        password = 'xxxxxxxx'
        smtp.login(username, password)
        sender = 'xxxxxxx@qq.com'
        receiver = 'xxxxxxx@qq.com'
        #发送邮件文本内容
        subject = '信息更改'
        msg = MIMEMultipart('mixed') 
        msg['Subject'] = subject
        msg['From'] = 'xxxxxx@qq.com <xxxxxxx@qq.com>'
        msg['To'] = 'xxxxxxxx@qq.com'
        # msg['Date'] = '2021-1-23'
        text = AllInfo
        text_plain = MIMEText(text, 'plain', 'utf-8')
        msg.attach(text_plain)
        # text = 'Hello World'
        # text_plain = MIMEText(text, 'plain', 'utf-8')
        smtp.sendmail(sender, receiver, msg.as_string())
        smtp.quit()
        tkinter.messagebox.showinfo(title='提示', message='发送成功')

def clearText():
    # myFile = open('C:/Users/Administrator/Desktop/python文件/spide/new.txt','w')
    # myFile.close() 
    tkinter.messagebox.showinfo(title='提示', message='开发者有点菜,该功能还未开放,请联系管理员MyNameIsChenWenHan')

sendTotextButton = tk.Button(window, text='添加', width=20, height=2, command=writeInText)
sendTotextButton.place(x=100, y=230)
tkinter.messagebox.showinfo(title='提示', message='使用方法:输入云战役打卡账号密码等点击添加即可实现每日自动打卡')
clearTextButton = tk.Button(window, text='清除用户数据', width=20, height=2, command=clearText)
clearTextButton.place(x=320, y=230)


window.mainloop()

写在最后:

有很多的不足,例如资料是存在txt里面的,客户信息的传递是通过邮件的。其实应该是用数据库搞得,不过没时间了,也不想搞了附上数据库连接代码,希望有缘人搞搞

import pymysql
 
# 打开数据库连接
db = pymysql.connect(host="192.168.xxx.xxx",user="xxxx",password="xxxxx",database="xxxxxxx")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
 
print ("Database version : %s " % data)
 
# 关闭数据库连接
db.close()
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
引用中提到了关于腾讯函数的使用,其中使用了requests库来进行请求。引用中也提到了使用requests库来请求接口。requests库是一个常用的Python库,用于发送HTTP请求。它提供了简洁而且直观的API,使得发送HTTP请求变得更加容易。 使用requests库,可以发送各种类型的HTTP请求,包括GET请求和POST请求。在函数中,通过使用requests库发送HTTP请求,可以与其他API进行通信,获取需要的数据或执行相应的操作。 在引用中的代码示例中,使用requests库实现了发送POST请求来进行打卡操作。在引用中的代码示例中,也使用了requests库来请求接口并获取access_token。 因此,函数中的requests是指使用requests库来发送HTTP请求,并与其他API进行交互。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [学校战役自动打卡系统——基于python requests模块及腾讯函数实现](https://blog.csdn.net/weixin_46486156/article/details/113555818)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Python调用百度API识别表格识别](https://download.csdn.net/download/weixin_38752282/13741881)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值