current position:Home>Python can actually realize the freedom of punch in?

Python can actually realize the freedom of punch in?

2022-02-02 05:25:23 Pike pik

Requirements describe

We need to log in to the attendance system ( Web side , Non mobile terminal ) Check in , If you don't want to get up early every day and punch in , You can write a program to achieve this function .

Business arrangement

Find the rules by getting up early and checking in for a long time , I just click every day , Sign in , All regular operations , Why not write a program to add Windows Realize automatic check-in , In this way, I don't have to spend time on the small matter of clocking in every day . Do as you say , I found that my daily clock in behavior can be summarized as " Login system --》 enter one user name 、 password --》 Click click --》 Exit the system ".

One day online browsing community , All of a sudden selenium Description of , Then check the relevant materials and find ,

selenium This thing is quite easy to use . In a word, it is selenium Will help us automatically enter the user name and password and click on something , It just coincides with my needs .

As for the selenium How to install this thing , I won't make wheels again . I installed webdriver It's Firefox , Because the attendance system is wonderful , Only Firefox login is allowed . As for the idea of procedure , I designed it like this , Put the user name and password in json In file , then Python Read out ,selenium Help me log in , Sign in , Exit the system, etc , After signing in, you will send me an email . therefore , You can also learn from this article Python How to read json file ,Python How to use e-mail and other knowledge , You can kill many birds with one stone .

Program realization

Packages that need to be imported ,from selenium import webdriver From selenium Import webdriver

Random dwell time , Indicates random delay 6 Seconds to 10 Time between seconds

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

Clear the user name box and password box , At the same time, from the set json Get username and password , Sign in ,clear The method is to clear the existing input data in the current window

And then you need to go through find_element_by_css_selector、find_element_by_xpath、find_element_by_id And other methods to click the corresponding button , In general, through css perhaps id perhaps name Generally, you can find the value of the button , If it doesn't work , You can find the of the button through the extension program on Firefox xpath, If other properties are not easy to determine , Just use find_element_by_xpath, This is basically omnipotent .

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

from json Get user information from the configuration file of 、 password , Here you can see Python How to read json Of documents

userinfo.json The user name and password information are shown in the figure below , Save it in the current directory

Send email notification

main Method to perform scheduling

It can be executed manually ,python

You can also join Windows Among the scheduled tasks

Program or script fill in , Under designation Python Installation path for


Add parameter , Indicates the path where the check-in script is located

E:\1.4-Python Source data \ Auto check in script -python-(4.0 edition )-2\

From , Indicates the directory in which the scheduled task is operated when it is started , Because of my json Configuration files are also in E:\1.4-Python Source data \ Auto check in script -python-(4.0 edition )-2, So I also fill in

E:\1.4-Python Source data \ Auto check in script -python-(4.0 edition )-2


This article realizes how to use python+ selenium Realize automatic check-in on the web page , And add to Windows How to operate in the scheduled task of . Except punch in , You can also use this program to do something else , Draw inferences from one instance , From now on, you don't have to order any more .

copyright notice
author[Pike pik],Please bring the original link to reprint, thank you.

Random recommended