Python

  最近对于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()
导出Excel文件
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
分析Excel数据
def main():

    check_file() 

    drvier=webdriver.Chrome()

    drvier.maximize_window()

    drvier.implicitly_wait(5)  #设置隐性等待时间

    IT()

    analysics()




if __name__=='__main__':

    main()
主函数
原文地址:https://www.cnblogs.com/yimihua-kai/p/12066283.html