最近對於python的第三方庫pandas比較有興趣,在學習的過程中也簡單的結合selenium做了一個簡單的小工具
最新公司用一個外部系統來記錄,追蹤BUG,可是這個系統並不是專業的BUG管理系統,所以對於數據篩選,查看不是很友好。無法滿足日常需求,所以就只能自己來倒騰一下了.這里只是實現了很簡單的小功能,我需要得出每天關閉BUG的數量 (暫時沒有做界面,也沒有封裝成exe)
主要用的定位方法為xpath,只是用到了很皮毛的程度,這個pandas工具對於數據處理的方面還是比較強大的,后續可以做更多的數據分析方面的練習

#!/usr/bin/env python3 # -*- coding: utf-8 -*- from selenium import webdriver import datetime,time import pandas as pd import os path =r"" url="" dt = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") dt=dt.strftime('%Y-%m-%d %H:%M:%S') #獲取當前凌晨的時間后,將其轉換為'str' #判斷下載路徑下是否存在之前下載的文件,有的話刪除 def check_file(): for root,dirs,files in os.walk(path): for name in files: if name.startswith('_itServiceItsuesList_'): os.remove(os.path.join(root,name)) print("Delete File:"+os.path.join(root,name)) else: pass

#登錄 def login(url): drvier.get(url) time.sleep(1) drvier.find_element_by_id('loginid').click() time.sleep(1) drvier.find_element_by_id('loginid').send_keys("") time.sleep(1) drvier.find_element_by_id('userpassword').click() drvier.find_element_by_id('userpassword').send_keys("") time.sleep(1) drvier.find_element_by_id('login').submit() time.sleep(3) return drvier

#去掉指定的位置,按照一定的規則篩選數據,導出excel def IT(): driver=login(url) driver.find_element_by_link_text(u'服務台').click() driver.find_element_by_link_text(u'待辦問題').click() fr=driver.find_element_by_xpath('//*[@id="mainframe"]') driver.switch_to.frame(fr) driver.find_element_by_xpath('//*[@id="shortcut$text"]').click() driver.find_element_by_xpath('//*[@id="mini-25$1"]/td[2]').click() #由我創建 driver.find_element_by_xpath('//*[@id="type"]/span/span/span[2]/span').click() #事件狀態 time.sleep(2) driver.find_element_by_xpath('//*[@id="mini-7$ck$14"]').click() #關閉 #driver.find_element_by_xpath('//*[@id="mini-7$ck$all"]').click() #全選 driver.find_element_by_xpath('//*[@id="type"]/span/span/span[2]/span').click() driver.find_element_by_xpath('//*[@id="a1"]/span').click() #查詢 driver.find_element_by_xpath('//*[@id="queryForm"]/div/table[5]/tbody/tr/td[1]/a[2]/span').click() #導出excel time.sleep(3) # driver.find_element_by_xpath('//*[@id="winSearch"]/div/div[2]/div[3]/div/a[1]/span').click() #導出按鈕 time.sleep(8) #等待下載完成 driver.close()

def analysics(): name=[n for n in os.listdir(path) if n.startswith('_itServiceItsuesList_')] #獲取已XX文件命名的文件 root=os.path.join(path,name) df=pd.read_excel(root) data=df.shape # 獲取總行與總列數 (行,列) data_rows=data[0] #獲取總行數 count=0 for row in range(data_rows): str_=str((df.loc[row])[72]) if str_!='nan': if str_>dt: #print((df.loc[row])[72]) count+=1 else: pass else: pass print(count) return count

def main(): check_file() drvier=webdriver.Chrome() drvier.maximize_window() drvier.implicitly_wait(5) #設置隱性等待時間 IT() analysics() if __name__=='__main__': main()