基于python+selenium自动健康打卡的实现代码


Posted in Python onJanuary 13, 2021

每天都要记得健康打卡

尊敬的老师,我忘了这次的健康打卡,反思的时候我想了很多东西,反省了很多事情,自己也很懊悔,触犯了学校的规定,深刻认识到自己所犯错误的严重性… 卡!那是小学生才有的检讨。作为一个有点懒的人,对于每次的健康打卡,都是做着重复性的填写,这让本人很是头疼,那就找找止疼药吧

使用的工具

需要有一定的python,html基础,和实践能力(毕竟实践出真知,实践能力强,你可以忽略前两个,你是最棒的!):

  • Pycharm ,在pycharm官网里面下载社区版或专业版(没其他的用途推荐用社区版);
  • Python 我使用的是python3.8,在官网下载,可参考python安装,配置好环境变量方便cmd 装包;
  • Selenium在cmd输入 pip install selenium ,分布式自动化测试工具,用于模拟用户在浏览器的行为;
  • Chromedriver 这个是在pycharm里面驱动Chrome浏览器,下载后解压放在Script下面,Chromedriver需要和自己的谷歌浏览器版本相对应

基于python+selenium自动健康打卡的实现代码

置于桌面 将你写好的py文件放在桌面或者你设置开机自启动管理运行该程序就可以了

基于python+selenium自动健康打卡的实现代码 

接下来就是代码了

代码中必要的地方都进行了注释,注释的多的地方就是我停留较久的地方,,,实习自动打卡的功能算是实现了,但还是有一些问题,比如说网络延时,当网页还未加载出来,你就无法定位该html元素,该程序就无法正常执行完操作,可以发一封邮件提醒你补填。欢迎大家共同探讨遇到的问题或者文章中有其他不足之处还望雅正。

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

# 脚本自动登录该网页
driver = webdriver.Chrome()
# 将健康表的地址copy过来就行
driver.get("你的健康表地址")
time.sleep(2)

print("开始点击----立即登录")
# 第一次点击登录跳转
driver.find_element_by_xpath('//*[@id="header-login-btn"]').click()
time.sleep(5)

print("开始点击快速登录")

# # selenium判断元素是否可以点击或者处理
# element = driver.find_element_by_id("img_out_191736586")

# element = driver.find_element_by_xpath('//*[@id="img_out_191733686"]')
# bianji = element.is_enabled() #是否可以编辑,或者按钮是否可以点击
# xinashi = element.is_displayed() #:判断元素是否显示
# xunazhong = element.is_selected() #:判断元素是否选中状态
# print(bianji,xinashi,xunazhong)
# element.click()

# 想了想为啥定位不到那个快速登录元素,原来html知识不够,切进iframe
driver.switch_to.frame(0) # 1.用frame的index来定位,第一个是0
# driver.switch_to.frame("frame1") # 2.用id来定位
# driver.switch_to.frame("myframe") # 3.用name来定位
# driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) # 4.用WebElement对象来定位

# 快捷登录
driver.find_element_by_xpath('//*[@id="img_out_1917336586"]').click()
# driver.find_elements_by_class_name('img_out_focus')[0].click()
time.sleep(15)

print("点击大数据人工智能一班SHEET")
# driver.find_elements_by_class_name("sheet-tab-name")[2].click()
driver.find_element_by_xpath('//*[@id="sheetbar"]/div[2]/div[3]/div/div[4]/span').click()
time.sleep(3)

print("开始点击更多")
driver.find_element_by_xpath('//*[@id="toobarMoreButton"]/div/div/div[1]').click()
# driver.find_element_by_class_name("toolbar-menu-button-more toolbar-inline-block").click()
time.sleep(10)

print("点击搜索")
driver.find_elements_by_xpath('//*[@id="sheet-search-button"]/div/div/div')[1].click()
time.sleep(3)

print("开始点击搜索框")
getinput = driver.find_element_by_xpath('//*[@id="search-panel-input"]')
getinput.send_keys("北极熊")
time.sleep(2)
print("已获取该位置" + getinput.location)
time.sleep(2)

# Key.tab选择,Kys.enter确定结束
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("")
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("是")
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("是")
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("否")
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("否")
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id('alloy-simple-text-editor').click()
driver.find_element_by_id('alloy-simple-text-editor').send_keys("填写你的地址")
driver.find_element_by_id('alloy-simple-text-editor').send_keys(Keys.ENTER)
time.sleep(1)

小结

上面的代码是根据我所填写的健康表流程写的,或许你并不能直接拿过去用,(这也正是我所期望的,哈哈),但是里面的功能实现比较清楚的,这样你就可以按照你的流程写代码了。Good good study, day day up.

到此这篇关于基于python+selenium自动健康打卡的文章就介绍到这了,更多相关selenium自动健康打卡内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python paramiko实现ssh远程访问的方法
Dec 03 Python
Python基础语法(Python基础知识点)
Feb 28 Python
轻松理解Python 中的 descriptor
Sep 15 Python
使用numba对Python运算加速的方法
Oct 15 Python
Python多线程应用于自动化测试操作示例
Dec 06 Python
pyqt5实现按钮添加背景图片以及背景图片的切换方法
Jun 13 Python
python制作简单五子棋游戏
Jun 18 Python
Django Aggregation聚合使用方法解析
Aug 01 Python
Python3打包exe代码2种方法实例解析
Feb 17 Python
在python中logger setlevel没有生效的解决
Feb 21 Python
python实现监听键盘
Apr 26 Python
一行Python命令实现批量加水印
Apr 07 Python
Python爬虫scrapy框架Cookie池(微博Cookie池)的使用
Jan 13 #Python
matplotlib交互式数据光标实现(mplcursors)
Jan 13 #Python
Python 生成短8位唯一id实战教程
Jan 13 #Python
python uuid生成唯一id或str的最简单案例
Jan 13 #Python
全网最全python库selenium自动化使用详细教程
Jan 12 #Python
[原创]赚疯了!转手立赚800+?大佬的python「抢茅台脚本」使用教程
Jan 12 #Python
五分钟学会怎么用python做一个简单的贪吃蛇
Jan 12 #Python
You might like
PHP读取MySQL数据代码
2008/06/05 PHP
PHP 在线翻译函数代码
2009/05/07 PHP
php 文件缓存函数
2011/10/08 PHP
php 无法加载mysql的module的时候的配置的解决方案引发的思考
2012/01/27 PHP
Ajax+PHP快速上手及简单应用说明
2013/07/24 PHP
实例讲解PHP表单处理
2019/02/15 PHP
Javascript创建Silverlight Plugin以及自定义nonSilverlight和lowSilverlight样式
2010/06/28 Javascript
JQuery中关于jquery.js与jquery.min.js的比较探讨
2013/05/15 Javascript
javascript获取下拉列表框当中的文本值示例代码
2013/07/31 Javascript
JS+CSS实现模仿浏览器网页字符查找功能的方法
2015/02/26 Javascript
javascript中递归函数用法注意点
2015/07/30 Javascript
IONIC自定义subheader的最佳解决方案
2016/09/22 Javascript
js获取元素的标签名实现方法
2016/10/08 Javascript
vue中动态绑定表单元素的属性方法
2018/02/23 Javascript
详解vue 兼容IE报错解决方案
2018/12/29 Javascript
js实现倒计时器自定义时间和暂停
2019/02/25 Javascript
微信小程序实现授权登录
2019/05/15 Javascript
Vue实现计算器计算效果
2020/08/17 Javascript
python列表操作实例
2015/01/14 Python
Python中使用第三方库xlrd来写入Excel文件示例
2015/04/05 Python
使用Python的Flask框架来搭建第一个Web应用程序
2016/06/04 Python
Python 基础教程之str和repr的详解
2017/08/20 Python
对Python正则匹配IP、Url、Mail的方法详解
2018/12/25 Python
Python 通过requests实现腾讯新闻抓取爬虫的方法
2019/02/22 Python
python使用beautifulsoup4爬取酷狗音乐代码实例
2019/12/04 Python
HTC VIVE美国官网:VR虚拟现实眼镜
2018/02/13 全球购物
黄色火烈鸟:De Gele Flamingo
2019/03/18 全球购物
在线课程:Skillshare
2019/04/02 全球购物
美国二手复古奢侈品包包购物网站:LXRandCo
2019/06/18 全球购物
奥地利体育网上商店:Gigasport
2019/10/09 全球购物
Agoda中文官网:安可达(低价预订全球酒店)
2021/01/18 全球购物
关于运动会的口号
2014/06/07 职场文书
教师节大会主持词
2015/07/06 职场文书
军训新闻稿范文
2015/07/17 职场文书
vue backtop组件的实现完整代码
2021/04/07 Vue.js
深入探讨opencv图像矫正算法实战
2021/05/21 Python