用python写的考勤自动打卡程序

打卡程序

from selenium import webdriver
import webbrowser
import time,datetime
import random
import configparser

#自动获取次日,如果有需要可以用这段
# def getday(msg,default=1):
#     r=input(msg)
#     if r=='':
#         return default
#     return r

#在指定位置读取文件
cf = configparser.ConfigParser()
cf.read(r"D:\Program Files (x86)\config.ini")
namee = cf.get("conf", "Na")
passd = cf.get("conf", "Pa")
Hour = cf.getint("conf", "H")
M1 = cf.getint("conf", "M1")
M2 = cf.getint("conf", "M2")
XB = cf.get("conf", "XB")
tdate = cf.getint("conf", "Interval")
ZD = cf.get("conf", "ZD")
DATE1 = cf.get("conf", "DATE1")

today = datetime.date.today()
h = int(Hour)
m = random.randint(M1, M2)
s = random.randint(0, 59)

if ZD=='on' : 
    D1 = DATE1.split('-', 2)
    halloween = datetime.datetime(int(D1[0]), int(D1[1]), int(D1[2]), h, m, s)
# tdate = int(getday("请输入间隔天:"))
else:
    tomorrow = today + datetime.timedelta(days=tdate)
    halloween = datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, h, m, s)
print(halloween)
while datetime.datetime.now() < halloween:
    time.sleep(1)
    
browser = webdriver.Chrome()
browser.get('http://登陆链接/Login') 
time.sleep(2)
browser.find_element_by_id("UserName").clear()
browser.find_element_by_id("UserName").send_keys(namee)
browser.find_element_by_id("PassWord").send_keys(passd)
browser.find_element_by_css_selector("[type=submit]").click()
time.sleep(1)
if XB=="on":    
    browser.find_element_by_class_name("btn").click()
    time.sleep(2)
    browser.switch_to_alert().accept()
time.sleep(3)
print('done')
# browser.close()

browser.quit()

"""
放置驱动
C:\Program Files\Python36\Scripts
https://npm.taobao.org/mirrors/chromedriver
打包
cd D:\python_study\打包\XBLS14
D:
pyinstaller -F -i test.ico test.py
-----------------------------------------------
D:\Program Files (x86)\config.ini
[conf]
Interval=1
Na=你的用户名
Pa=密码
H=8
M1=44
M2=58

#下班填入on或者其它
XB=ond

#指定日期on或者其它
ZD=on4
DATE1=2019-10-08
"""



猜你喜欢

转载自www.cnblogs.com/young886/p/12454680.html