设为首页 加入收藏

TOP

过年回家抢票,让光猫自动重启的小脚本
2019-02-11 10:07:55 】 浏览:104
Tags:过年 回家 自动 重启 脚本
 1 from selenium import webdriver
 2 from time import sleep
 3 import datetime
 4 url = "http://192.168.1.1/login_smart.html"
 5 url_login = "http://192.168.1.1/login.cgi"
 6 url_longout = "http://192.168.1.1/login.cgi#"
 7 Rstart_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 8 i = 0
 9 def write_record(now_log):
10     with open(r"C:\Users\brian\Desktop\RestartLogs\log.txt","r+"
 
			
00">) as f:
11 old = f.read() 12 f.seek(0,0) 13 f.writelines(now_log) 14 f.writelines('\n') 15 f.writelines(old) 16 f.close() 17 18 while True: 19 try: 20 dr = webdriver.Chrome() 21 dr.get(url) 22 dr.maximize_window() 23 sleep(0.1) 24 dr.find_element_by_css_selector("#loid_user").clear() 25 sleep(0.1) 26 dr.find_element_by_css_selector("#loid_user").send_keys("useradmin") 27 sleep(0.1) 28 dr.find_element_by_css_selector("#loid_pwd").send_keys("a124689a") 29 sleep(0.1) 30 dr.find_element_by_css_selector("#save_loid").click() 31 sleep(10) 32 if dr.current_url == url_login: 33 print("登录成功") 34 dr.find_element_by_css_selector("[alt='重启']").click() 35 sleep(0.1) 36 dr.find_element_by_css_selector("#okbutton1").click() 37 if dr.current_url == url_longout: 38 new_log = "重启成功,重启时间是:%s" %Rstart_time 39 print(new_log) 40 write_record(new_log) 41 dr.quit() 42 break 43 else: 44 dr.quit() 45 print("重启失败了,关闭浏览器再来") 46 continue 47 except: 48 dr.quit() 49 print("代码运行出错,关闭浏览器再来") 50 i = i +1 51 if i >= 3: 52 break 53 else: 54 continue

 


编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python socket的客户端 下一篇大牛推荐的10本学习 Python 的好书

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(217) }