python实现上下班全自动打卡

前言:
由于每天都需要通过网页上下班打卡这样重复性很高的操作且用户名密码不变,因此采用了自动化打卡的方式来替代。
环境:


image.png

架构:
python+selenium
浏览器:
chrome81.0.4044.113(正式版本) (32 位)
前期准备:
安装python3.8.3(请见下一篇文章)
安装pip(请见下一篇文章)
安装chrome driver(略)
原代码:

# -*- coding: UTF-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
import random
import smtplib
from email.mime.text import MIMEText
import time
import json
from lxml import etree


driver = webdriver.Chrome()
driver.get("http://xx.xx.xx.x")
now_handle = driver.current_window_handle
driver.switch_to_window(now_handle)
driver.find_element_by_id("username").clear()
driver.find_element_by_id("password").clear()
driver.find_element_by_id("username").send_keys("xxx")
driver.find_element_by_id("password").send_keys("xxxx")
driver.find_element_by_css_selector("button.ewb-submit").click()
driver.maximize_window()
driver.find_element_by_xpath('//*[@id="firstmenu"]/li[10]').click()
sleep(5)
driver.find_element_by_xpath('//*[@id="mini-54"]/span').click()
sleep(5)
driver.find_element_by_xpath('//*[@id="addClose"]/span').click()
sleep(5)
driver.find_element_by_css_selector("mini-button mini-state-default mini-corner-all mini-messagebox-button ok").click()
配置计划任务:
![image.png](https://upload-images.jianshu.io/upload_images/10401528-057bc56b961f19d4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


![image.png](https://upload-images.jianshu.io/upload_images/10401528-a484fe5ff1d04c75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


目前仅适用于单人,如果需要完成多人打卡,可以在此基础上进行优化。
完成效果图
![image.png](https://upload-images.jianshu.io/upload_images/10401528-6d32e782880ec8e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![image.png](https://upload-images.jianshu.io/upload_images/10401528-209edce6fd7bf29a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
会有报错信息,不过没关系,不影响运行,如果有强迫症可以将代码再优化。
            
         
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容