好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python+selenium实现简易地疫情信息自动打卡签到功能

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

这时候就该模拟登录了,首先找到用户名的input框。按ctrl+shift+c,打开开发者工具,点击用户名右边的input框,即可在右边的开发者工具中找到input框对应的代码。


右击该模块,点击copy->copy Xpath 。(Xpath是用来定位该input控件位置的)

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)

账号密码输完了,就该点击登陆了。按ctrl+shift+c,点击登录按钮,在右边的开发者工具对应的代码块右键copy->copy xpath,获得button的xpath。

driver.find_element_by_xpath('//*[@id="changeBack"]/tbody/tr/td[2]/table[1]/tbody/tr[2]/td/p/input[1]').click()
#通过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()

完整的程序:

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()

相关学习推荐:编程视频

以上就是python+selenium实现简易地疫情信息自动打卡签到功能的详细内容!

查看更多关于python+selenium实现简易地疫情信息自动打卡签到功能的详细内容...

  阅读:51次