Python realizes automatic clocking
As a student, I often forget to clock in manually and be reminded by the class committee...
So the liver has a clock-in program that can run automatically as long as I turn on the computer every day.
Never urge me to punch in...
Idea: Simulate manual clocking through selenium
Prepare
①selenium library
②chrome driver ③configure
environment variables
Code
Load library
from selenium import webdriver
import time
Enter the browser settings to change the user agent into mobile mode
options = webdriver.ChromeOptions()
options.add_argument('user-agent=Mozilla/5.0 (Linux; Android 9; V1838A Build/PKQ1.190302.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.89 Mobile Safari/537.36 T7/11.20 SP-engine/2.16.0 baiduboxapp/11.20.0.14 (Baidu; P1 9)')
Open the browser to enter the check-in website
browser = webdriver.Chrome(options=options)
url = "https://xsc-health.wh.sdu.edu.cn/mobile/index.html?a=b#/common/office/fightncp/home"
browser.get(url)
Prepare password
name = "202000820***"
word = 'whsdu@202000820***'
time.sleep(2)
Get the id of the username and enter
username = browser.find_element_by_name('username')
username.send_keys(name)
Get the id of the password and enter
username = browser.find_element_by_name('password')
username.send_keys(word)
time.sleep(3)
Click to Login
browser.find_element_by_class_name('weui-btn-area').click()
time.sleep(3)
Enter the clock
browser.find_element_by_xpath("//*[contains(text(),'打卡')]").click()
time.sleep(3)
Submit check-in
browser.find_element_by_xpath("//*[contains(text(),'提交')]").click()
time.sleep(5)
Close the browser
browser.quit()
bug
10.16 clocking solve computer can not open the website
10.17 to resolve a bad gps signal can not locate the cause blocking element, can not find a submit element
10.18 to resolve to start automatically punch