How to use python to realize automatic check-in? You will know after reading it

[How to use Python to realize automatic check-in]

Description of Requirement

We need to log in to the attendance system (webpage, non-mobile terminal) to sign in. If you don't want to get up early every day to check in, you can write a program to achieve this function.

Business combing

After a long time of getting up early and checking in, I found the rules. I just keep clicking and checking in every day. They are all regular operations. Why don’t I write a program and add it to Windows to realize automatic sign-in, so that I don’t have to spend time every day. Check in on this little thing. Just do it, I found that my daily check-in behavior can be summarized as "login to the system –" enter the user name and password – "click click – "exit the system".

One day when I browsed the community on the Internet, I suddenly saw the description of selenium, and then checked the relevant information and found that,

Selenium is quite easy to use. In one sentence, selenium will help us automatically enter the user name and password and click on something, which happens to coincide with my needs.

As for how to install selenium, I won't repeat the wheel. The webdriver I installed is Firefox, because this attendance system is very weird, only Firefox is allowed to log in. As for the idea of ​​the program, I designed it like this, put the username and password in the json file, and then read it with Python. Selenium helps me log in, sign in, and exit the system, etc. After the sign in is completed, it will send me an email. . Therefore, from this article, you can also learn how Python reads json files, how Python uses mailboxes to send emails, etc. It really serves multiple purposes.

program implementation

The package that needs to be imported, from selenium import webdriver means importing webdriver from selenium

Random stay time, which means a random delay between 6 seconds and 10 seconds

Open the login attendance system, webdriver.Firefox() means to open a Firefox window

Clear the user name box and password box, and get the user name and password from the set json at the same time, log in, the clear method is to clear the existing input data in the current window

Then you need to click the corresponding button through find_element_by_css_selector, find_element_by_xpath, find_element_by_id and other methods. Generally, you can find the value of the button through css or id or name. If it is not possible, you can find the button through the extension program on Firefox xpath, if other attributes are not easy to determine, use find_element_by_xpath, which is basically omnipotent.

Set the account password information of the person who needs to sign in. At first, I directly specified it in the string array. Later, in order for the software to be widely used, I added the json configuration file

Obtain user information and password from the json configuration file, here you can see how Python reads the json file

The username and password information of userinfo.json is as shown in the figure below, just save it in the current directory

Send email notification

main method execution scheduling

It can be executed manually when executing, python qiandao-4-0.py

It can also be added to the scheduled tasks of Windows

Fill in the program or script, specify the installation path of Python

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

Add parameters to indicate the path where the sign-in script is located

E:\1.4-Python source data\automatic sign-in script-python-(4.0 version)-2\qiandao-4-0.py

Starting from means which directory the scheduled task is operated in when it starts, because my json configuration file is also in E:\1.4-Python source data\automatic sign-in script-python-(4.0 version)-2 , so I also fill in

E:\1.4-Python source code information\Automatic sign-in script-python-(version 4.0)-2


Summarize

This article realizes how to use python+ selenium to realize automatic sign-in on the webpage, and how to add it to the scheduled task of Windows. In addition to clocking in, you can also use this program to do other things, and you will never need to click again.

In the end, I sorted out some learning materials by myself, which were shared with me by others. I hope it will be helpful to you.

Click here to get it for free: CSDN spree: "Python learning route & full set of learning materials" free sharing

Python Study Outline

The technical points in all directions of Python are sorted out to form a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources according to the above knowledge points to ensure that you can learn more comprehensively.
insert image description here

2. Essential development tools for Python

insert image description here

3. Introductory learning video

Four Python practical cases

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.
insert image description here
insert image description here
This full version of the full set of Python learning materials has been uploaded to CSDN. If you need it, you can private message me to get it for free [100% free guarantee]

Guess you like

Origin blog.csdn.net/m0_59162248/article/details/129733795