Requirements describe

We need to log in to the attendance system (web, not mobile) to check in. If we don’t want to get up early every day to punch in, we can write a program to do this.

The business card

I found the rule by getting up early for a long time and checking in. I just kept clicking and checking in every day, which was regular operation. Why don’t I write a program and add it to Windows to realize automatic checking in, so THAT I don’t have to spend time on the small matter of punching in every day? I found that my daily punching can be summed up as “log in — enter username and password –” click click — “log out of the system”.

One day, I was surfing the community, and suddenly I saw the description of Selenium, and I looked it up and found,

Selenium is quite useful. In a nutshell, Selenium helps us automatically enter username, password, and click on something, which is exactly what I need.

As for how to install selenium, I will not duplicate the wheel. I installed WebDriver in Firefox, because the attendance system is weird and only allows Firefox login. As for the design of the program, I put the user name and password in json file, and then Python will read it. Selenium helps me to log in, check in, log out of the system, etc. After checking in, I will also send an email to me. So, from this article, you can also learn how Python reads JSON files and how Python sends emails using mailboxes.

Program implementation

From Selenium import WebDriver indicates that webDriver is imported from Selenium

Random dwell time: indicates the random delay between 6 and 10 seconds

Open the login attendance system, webDriver.firefox () to open a Firefox window

Clear the user name and password boxes and obtain the user name and password from json. Log in to clear the existing input data in the current window

And then you need to click the corresponding button using find_element_by_css_selector, find_element_by_xpath, find_element_by_id, etc. It is generally possible to find the value of the button using CSS or id or name. If this is not possible, you can use the Firefox extension to find the xpath for the button. If all other attributes are difficult to determine, use find_element_by_xpath.

To set the account password information of the person who needs to check in, I directly specified it in the string array at first, and later added json configuration file for the software to be widely used

Get the user information and password from the JSON configuration file. See how Python reads the JSON file

Json The following figure shows the user name and password. Save the password in the current directory

Sending Email Notifications

The main method performs scheduling

Python qiandao-4-0.py can be executed manually

It can also be added to Windows scheduled tasks

Program or script to specify the Python installation path

D: \ WinPython – 64 – bit – 3.4.4.4 Qt5 \ python – 3.4.4 amd64 \ python exe

Add a parameter to the path where the script is checked in

E:\1.4-Python source code \ automatic check-in script -Python – (version 4.0) -2\qiandao-4-0.py

Began, where is says timing task start time is operating under a directory, because of my json configuration file also in E: \ 1.4 \ Python source data automatic sign-in script – Python (version 4.0) – 2, therefore I also fill in

E:\1.4- Automatic check-in script -Python – (version 4.0) -2

conclusion

This article has shown how to implement automatic check-in on web pages using Python + Selenium and how to add it to Windows scheduled tasks. You can also use this program to do something other than punch in, so you don’t have to click anymore. Thank you for giving me a thumbs-up