码迷,mamicode.com
首页 > 编程语言 > 详细

python-利用senleium实现定时重启路由器

时间:2019-01-22 21:56:13      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:route   %s   selenium   seconds   key   driver   end   定时   content   

from selenium import webdriver
import time
#from datetime import *
#import sendmessage
def restart_router():
    try:
        browser = webdriver.Chrome()
        browser.get("http://192.168.1.1")
        browser.implicitly_wait(30)
        browser.find_element_by_xpath("//*[@id=‘pcPassword‘]").send_keys("haohao123")
        browser.find_element_by_id("loginBtn").click()
        time.sleep(5)
        browser.switch_to_frame("bottomLeftFrame")
        browser.find_element_by_xpath(//*[@id="a39"]).click()
        browser.find_element_by_xpath(//*[@id="a45"]).click()
        browser.switch_to_default_content()
        browser.switch_to_frame("mainFrame")
        browser.find_element_by_xpath(//*[@id="reboot"]).click()
        time.sleep(5)
        browser.switch_to_alert().accept()
        time.sleep(20)
    finally:
        browser.quit()

if __name__ == __main__:

    while True:
        try:
            interval=60*80
            time_remaining = interval - time.time() % interval
            print("Sleeping until %s (%s seconds)..." % ((time.ctime(time.time() + time_remaining)), time_remaining))
            print(time_remaining)
            time.sleep(time_remaining)
            print("Starting command.")
            restart_router()
            print(重启路由器成功)
            print("-"*100)
        except Exception as e:
            print(e)

 

python-利用senleium实现定时重启路由器

标签:route   %s   selenium   seconds   key   driver   end   定时   content   

原文地址:https://www.cnblogs.com/liangyf/p/10305934.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!