admin管理员组文章数量:1625830
前言:1、每个chromedriver对应一个chrome版本
具体对应关系见:https://npm.taobao/mirrors/chromedriver/
2、如果selenium使用中出现找不到元素的问题,要么就是用了新的frame,要么就是页面还没刷新出来,用time.sleep()就可以了
3、关机的代码是:os.popen(‘at 16:50 shutdown -s’)
4、Pyinstaller如果环境是64位系统,做出来的程序就只能给64位电脑使用,如果要32位电脑用就必须用32位环境下做出来的程序!
5、程序创建快捷方式,拖到“开始”——“所有程序”——“启动”下面,就可以实现开机自动运行程序
代码如下:
from selenium import webdriver
import time
import os
def restart20():
browser = webdriver.Chrome()
url = "http://10.1.20.20"
browser.get(url)
#登陆页面
browser.find_element_by_xpath('//*[@id="szUserName"]').send_keys('admin') # 输入用户名
browser.find_element_by_xpath('//*[@id="szUserPasswdSrc"]').send_keys('admin123') # 输入密码
browser.find_element_by_xpath('//*[@id="login"]/span[2]').click() # 点击“登陆”
#设置页面
browser.find_element_by_xpath('//*[@id="config"]').click() # 点击“配置”
browser.switch_to.frame('container')
browser.find_element_by_xpath('//*[@id="ConfigLeft"]/div[25]/a').click() # 点击“系统维护”
browser.find_element_by_xpath('//*[@id="SystemMaintenance"]').click() # 点击“系统维护”-子菜单
time.sleep(1) #这里要暂停一秒,不然会造成识别不到元素
browser.find_element_by_xpath('//*[@id="RestartBtn"]').click() # 点击“重启”
#重启警示窗口
al = browser.switch_to_alert()
time.sleep(1)
al.accept()
print('10.1.20.20 重启成功,请等待1分钟!')
browser.quit()
def restart15():
browser = webdriver.Chrome()
url = "http://10.1.20.15"
browser.get(url)
time.sleep(3)
# 登陆页面
browser.find_element_by_xpath('//*[@id="username"]').send_keys('admin') # 输入用户名
browser.find_element_by_xpath('//*[@id="password"]').send_keys('admin123') # 输入密码
browser.find_element_by_xpath('//*[@id="login"]/table/tbody/tr/td[2]/div/div[5]/button').click() # 点击“登陆”
# 设置页面
time.sleep(5)
browser.find_element_by_xpath('//*[@id="nav"]/li[5]/a').click() # 点击“配置”
time.sleep(5)
browser.find_element_by_xpath('//*[@id="menu"]/div/div[2]/div[3]/span').click() # 点击“系统维护”
time.sleep(3)
browser.find_element_by_xpath('//*[@id="maintainUpgrade"]/div[1]/div[2]/span[1]/button').click() # 点击“重启”
time.sleep(1)
# 重启窗口
browser.find_element_by_xpath('//*[@id="config"]/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[3]/td/div/button[1]').click() # 点击“配置”
print('10.1.20.15 重启成功,请等待1分钟!')
browser.quit()
def open_browser():
browser = webdriver.Chrome()
url = "http://10.1.8.100:8089/zhyyt/gateway/homePage"
browser.get(url)
time.sleep(1)
browser.fullscreen_window() #全屏
for i in range(1, 10):
time.sleep(1800)
browser.refresh()
# #点击启动Adobe Flash Player
# browser.find_element_by_xpath('//*[@id="chemghvfsnuwfeuxwx"]').click()
# al = browser.switch_to_alert()
# time.sleep(1)
# al.accept()
def shuttime():
shuttime = input('请输入关机时间(16:55这样的格式,默认16:55):')
if shuttime == '':
shuttime = '16:55'
shut_computer = 'at '+ shuttime +' shutdown -s'
os.popen(shut_computer)
if __name__ == '__main__':
print('请不要关闭本窗口!最小化即可!')
os.popen('at 16:50 shutdown -s')
restart15()
restart20()
print("即将打开大屏网址,请不要关闭窗口!")
time.sleep(10)
open_browser()
版权声明:本文标题:用Python写了一个自动打开网页重启服务器,打开需要看的网页并全屏,最后自动关机的程序 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728934179a1180525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论