"""
# @Author: 狄克
# @Time : 2020/4/9 17:54
# @File : 疫情防控-自动打卡签到.py
最近在学自动化测试 感觉这个做自动打卡挺不错哎
工具说明:使用 Python + Selenium + ChromeDriver
需要将ChromeDriver加入环境变量
实现自动登陆疫情打卡页面并签到
"""
import time
from selenium import webdriver
from selenium.webdriver.support.select import Select
import yagmail
import datetime
userName = '2018******'
password = '******'
MainBox = '******@qq.com'
url = "http://****.****.edu.cn/jkdk"
NewTask_XPath = "/html/body/div[2]/table/tbody[2]/tr[2]/td[2]/a"
Address_XPath = "//*[@id='wjTA']/tbody/tr[6]/td[2]/div/select[2]"
Work_Xpath = "//*[@id='wjTA']/tbody/tr[6]/td[2]/div/select[3]"
Health_XPath = "//*[@id='wjTA']/tbody/tr[6]/td[2]/div/select[4]"
Life_XPath = "//*[@id='wjTA']/tbody/tr[6]/td[2]/div/select[5]"
Family_XPath = "//*[@id='wjTA']/tbody/tr[6]/td[2]/div/select[6]"
Submit_XPath = "/html/body/form/div[1]/table/tbody/tr/td[1]/input"
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def do_login(userName, password):
driver.find_element_by_id('txtId').send_keys(userName)
driver.find_element_by_id('txtMM').send_keys(password)
driver.find_element_by_id('IbtnEnter').click()
time.sleep(2)
def do_sign():
driver.find_element_by_xpath(NewTask_XPath).click()
time.sleep(2)
s1 = Select(driver.find_element_by_xpath(Address_XPath))
s2 = Select(driver.find_element_by_xpath(Work_Xpath))
s3 = Select(driver.find_element_by_xpath(Health_XPath))
s4 = Select(driver.find_element_by_xpath(Life_XPath))
s5 = Select(driver.find_element_by_xpath(Family_XPath))
s1.select_by_index(1)
s2.select_by_index(4)
s3.select_by_index(1)
s4.select_by_index(1)
s5.select_by_index(1)
time.sleep(2)
driver.find_element_by_xpath(Submit_XPath).click()
def sendMail(content):
yag = yagmail.SMTP("[email protected]", "GVVEZOBIJCRVNQWO", 'smtp.126.com')
yag.send(MainBox, "打卡提醒", content)
if __name__ == '__main__':
driver = webdriver.Chrome()
driver.get(url)
do_login(userName, password)
do_sign()
sendMail(nowTime + "\n打卡成功!")
print("打卡结束")
time.sleep(5)
driver.quit()