In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use Python to achieve automatic sign-in, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Requirement description
We need to log in to the attendance system (web side, non-mobile side) to check in. If you don't want to get up early and sign in every day, you can write a program to achieve this function.
Business carding
Through a long time to get up early and sign in to find the rule, I just keep clicking and signing in every day, which is a regular operation. Why not write a program and add it to Windows to achieve automatic check-in, so that I don't have to spend time on the little thing of signing in every day. Just do it, I found that my daily sign-in behavior can be summarized as "logging in to the system -" entering a user name and password-- "Click--" exit the system.
One day, when I was browsing the community on the Internet, I suddenly saw the description of selenium, and then looked up the relevant information and found
Selenium is quite easy to use. In a word, selenium will help us enter the user name and password automatically and click on it, which happens to coincide with my needs.
As for how to install the selenium, I won't repeat the wheel. The webdriver I installed is Firefox, because this attendance system is so weird that only Firefox is allowed to log in. As for the idea of the program, I designed it like this: put the user name and password in the json file, and then Python to read it. Selenium helps me log in, check in, log out of the system, etc., and send me an email after signing in. So, from this article you can also learn how Python reads json files and how Python uses mailboxes to send e-mails.
Program realization
The package to be imported. From selenium import webdriver means importing webdriver from selenium.
Random residence time, which represents a random delay of between 6 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. Log in. The clear method is to clear the input data already 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. In general, you can find the value of the button through css or id or name. If it really doesn't work, you can find the xpath of the button through the extension program on Firefox. If other attributes are not sure, use find_element_by_xpath, which is basically omnipotent.
To set the account password information of the person who needs to check in, at first I directly specified it in the string array, and later, in order for the software to be widely used, add the json configuration file
Get the user information and password from the json configuration file. Here you can see how Python reads the json file.
The userinfo.json username and password information is shown in the following figure, which can be saved in the current directory.
Send email notification
Main method executes scheduling
It can be executed manually, python qiandao-4-0.py.
You can also join Windows's scheduled tasks.
Fill in the program or script and specify the installation path of Python.
D:\ WinPython-64bit-3.4.4.4Qt5\ python-3.4.4.amd64\ python.exe
Add a parameter to indicate the path where the check-in script is located
E:\ 1.4-Python source data\ automatic check-in script-python- (version 4.0)-2\ qiandao-4-0.py
Starting from, which indicates the directory in which the scheduled task is operated when it starts, because my json configuration file is also in E:\ 1.4-Python source data\ automatic check-in script-python- (version 4.0)-2, so I also fill in
E:\ 1.4-Python source data\ automatic check-in script-python- (version 4.0)-2
Thank you for reading this article carefully. I hope the article "how to use Python to automatically sign in" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.