Python自动登录PRTG各节点,截取整个网页保存为图片
由于PRTG的流量图不是一张纯图片,所以采用截图整个网页的方式来保存, 脚本入下,使用前先配置环境。
#encoding = utf-8 import time, os import datetime from selenium import webdriver def reportdate(): monday,friday = datetime.date.today(),datetime.date.today() one_day = datetime.timedelta(days=1) while monday.weekday() != 0: monday -= one_day SDATE = monday.strftime('%Y-%m-%d-00-00-00') while friday.weekday() != 4: friday -= one_day EDATE= friday.strftime('%Y-%m-%d-23-59-59') return str('&sdate=')+str(SDATE)+str('&edate=')+str(EDATE) #return '&sdate=2020-03-02-00-00-00&edate=2020-03-06-23-59-59' #(报告是每周六或周日做,如果遇到下周补做,可手动设定return值) allsensors_id = ["12036","11625","9603","12044","9654","9569","9755","9772","9705","11472","9865","9718","9675","9736","9886","11525","11991","12207"] allsensors_name = ["HKG","BEJ","CDU","CKG","DLN","GZU","HZU","JNA","NJG","SHA","SHA_MCU","SUZ","SZN","TJN","WHN","XMN","TPE","MNG"] #(SensorsID可在PRGT该Sensors页面的Url中查看到) rundate=reportdate()[33:43] #rundate=datetime.date.today().strftime('%Y-%m-%d') urlhead='http://cngdcop01/historicdata_html.htm?&username=prtgadmin&password=XXXXX&avg=120&pctavg=300&pctshow=false&pct=95&pctmode=false&hide=-1,2,3,6,7,8,9,10,11,12,13,14&id=' graphs_path=str('C:\\Users\\lynguo\\Desktop\\PRTGCAP\\MPLS\\')+str(rundate)+str('\\') os.makedirs(graphs_path) driver = webdriver.Chrome() driver.set_window_size(1566, 892) for sid in range(len(allsensors_id)): sensors_id=allsensors_id[sid] sensors_name=allsensors_name[sid] sfullurl=(str(urlhead)+str(sensors_id)+str(reportdate())) driver.get(sfullurl) graphfile_path = str(graphs_path)+str('\\')+str(sensors_name)+str('.png') driver.get_screenshot_as_file(graphfile_path) time.sleep(3) driver.close()
运行结果