Python+selenium implements simple automatic check-in function for epidemic information

coldplay.xixi
Release: 2020-08-22 17:40:20
forward
2663 people have browsed it

Python+selenium implements simple automatic check-in function for epidemic information

[Related learning recommendations: python video tutorial]

Since the school requires us to check in and sign in the epidemic information on the official website every day, more or less It takes 1 minute to operate. The dignity of programmers tells us that we must not clock in manually. I happened to have learned selenium recently, so I spent 5 minutes drawing and writing a small program to automatically clock in and sign in.

Test environment: python3.7, selenium, chrome browser

The configuration of seleium and chromedriver will not be discussed here. Here is a link

First find the school information Portal login page:

Python+selenium implements simple automatic check-in function for epidemic information


#导入selenium中的webdriver
from selenium import webdriver
import time
url = 'http://my.hhu.edu.cn/login.portal' #信息门户的登陆页面
driver = webdriver.Chrome() # 初始化一个Chrome的驱动
driver.get(url) # 让自动化模块控制的Chrome浏览器跳转到信息门户登陆页面
Copy after login

It’s time to simulate login. First find the input box for the user name. Press ctrl shift c to open the developer tools, click the input box to the right of the user name, and you can find the code corresponding to the input box in the developer tools on the right.

Python+selenium implements simple automatic check-in function for epidemic information
Python+selenium implements simple automatic check-in function for epidemic information

Right-click the module and click copy->copy Xpath. (Xpath is used to locate the input control)

root = '' #赋值自己的用户名
password = '' # 赋值自己的密码
driver.find_element_by_xpath('//*[@id="username"]').send_keys(root) #将xpath赋值在前面的括号中,通过send_keys方法给input赋值

#类似的,赋值密码框的xpath,赋值密码
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
Copy after login

After entering the account password, it is time to click to log in. Press ctrl shift c, click the login button, right-click the code block corresponding to the developer tools on the right and copy->copy xpath to obtain the xpath of the button.

driver.find_element_by_xpath('//*[@id="changeBack"]/tbody/tr/td[2]/table[1]/tbody/tr[2]/td/p/input[1]').click()
#通过click方法点击登录框,跳转到登陆后的页面
Copy after login

Python+selenium implements simple automatic check-in function for epidemic information

On the page after logging in, I found the health reporting function box. Click on the function box and find that the page jumps to the check-in page: Python+selenium implements simple automatic check-in function for epidemic information

Copy the URL of the page and let the program jump to the page after logging in:

form = 'http://form.hhu.edu.cn/pdc/form/list'
driver.get(form)
Copy after login

Let the program click " Undergraduate health check-in:

driver.find_element_by_xpath('/html/body/p[1]/p[4]/p/section/section/p/a/p[2]').click()
Copy after login

will jump to the following page

Python+selenium implements simple automatic check-in function for epidemic information

Click submit to complete the check-in

driver.find_element_by_xpath('//*[@id="saveBtn"]').click()
Copy after login

Complete procedure :

from selenium import webdriver
import time
root = ''
password = ''
url = 'http://my.hhu.edu.cn/login.portal'
driver = webdriver.Chrome()
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys(root)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
driver.find_element_by_xpath('//*[@id="changeBack"]/tbody/tr/td[2]/table[1]/tbody/tr[2]/td/p/input[1]').click()
form = 'http://form.hhu.edu.cn/pdc/form/list'
driver.get(form)
driver.find_element_by_xpath('/html/body/p[1]/p[4]/p/section/section/p/a/p[2]').click()
driver.find_element_by_xpath('//*[@id="saveBtn"]').click()
Copy after login

Related learning recommendations: Programming video

The above is the detailed content of Python+selenium implements simple automatic check-in function for epidemic information. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!