#coding:utf-8 import os,sys,time import xlsxwriter from selenium import webdriver from selenium.webdriver.common.keys import Keys #定义工作目录 workdir = 'E:\\' #定义目前时间 current_time = time.strftime("%Y%m%d",time.localtime(time.time())) #定义截图函数CUTPAGE def CUTPAGE(*args,**kwargs): try: #谷歌浏览器对部分端口做限制,如6666。启动浏览器时加上--explicitly-allowed-ports=6666启动参数,解决ERR_UNSAFE_PORT问题 options = webdriver.ChromeOptions() options.add_argument('--explicitly-allowed-ports=6666') #executable_path为浏览器驱动程序所在位置 driver = webdriver.Chrome(executable_path='C:\Users\Administrator4\AppData\Local\Google\Chrome\Application\chromedriver.exe',options=options) driver.get(url) #窗口最大化 driver.maximize_window() #通过名字定位页面元素 username = driver.find_element_by_name('name') password = driver.find_element_by_name('password') login_button = driver.find_element_by_name('enter') #输入账号密码,并点击登录按钮 username.send_keys(account) password.send_keys(passwd) login_button.click() #js = "window.scrollTo(0,document.body.scrollHeight);" #driver.execute_script(js) #暂停5秒,观察zabbix首页 time.sleep(5) #截图 driver.save_screenshot(workdir+'zabbixpage'+current_time+'.png') except: print "Fail to capture a screenshot.Please confirm if the username and the password is true!" sys.exit(1) finally: #关闭浏览器 driver.close() #定义插入图片函数 def SAVETOEXCEL(): try: #定义excel工作薄 workbook = xlsxwriter.Workbook(workdir+u'XXXX-日常监控_'+current_time+'.xlsx') #增加工作薄sheet页 worksheet = workbook.add_worksheet() #确定图片是否存在 flag = os.path.exists(workdir+'zabbixpage'+current_time+'.png') if flag: #插入图片,并对插入图片进行缩放 worksheet.insert_image('A1',workdir+'zabbixpage'+current_time+'.png',{'x_scale':0.9,'y_scale':1.15}) except: print "Fail to insert image into excel" sys.exit(2) finally: workbook.close() if __name__ == '__main__': url = 'http://XXX.XXX.XXX.XXX:XXXX/index.php' account = raw_input(u"请输入登录zabbix的用户名:".encode('gbk')) passwd = raw_input(u"请输入登录zabbix的密码:".encode('gbk')) CUTPAGE(url=url,account=account,passwd=passwd) SAVETOEXCEL() flag = os.path.exists(workdir+'zabbixpage'+current_time+'.png') if flag: #删除图片 os.remove(workdir+'zabbixpage'+current_time+'.png')
zabbix监控页面自动截图
原文作者:RedCompu93
原文地址: http://blog.itpub.net/31541436/viewspace-2219861/
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: http://blog.itpub.net/31541436/viewspace-2219861/
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。