示例#1
0
 def __init__(self):
     self.cookieObj = CookieUtil()
     self.nowTile = time.strftime('%Y%m%d%H%M%S')
     self.nowPath = os.getcwd()
     if os.path.exists(self.nowPath + "/../log") == False:
         os.mkdir(self.nowPath + "/../log")
     if os.path.exists(self.nowPath + "/../result") == False:
         os.mkdir(self.nowPath + "/../result")
     self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
     self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
     self.check = Check()
     self.logUtil = LogUtil()
示例#2
0
 def __init__(self):
     self.cookieObj = CookieUtil()
     self.nowTile = time.strftime("%Y%m%d%H%M%S")
     self.nowPath = os.getcwd()
     if os.path.exists(self.nowPath + "/../log") == False:
         os.mkdir(self.nowPath + "/../log")
     if os.path.exists(self.nowPath + "/../result") == False:
         os.mkdir(self.nowPath + "/../result")
     self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
     self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
     self.check = Check()
     self.logUtil = LogUtil()
示例#3
0
class RunCode:
    def __init__(self):
        self.cookieObj = CookieUtil()
        self.nowTile = time.strftime('%Y%m%d%H%M%S')
        self.nowPath = os.getcwd()
        if os.path.exists(self.nowPath + "/../log") == False:
            os.mkdir(self.nowPath + "/../log")
        if os.path.exists(self.nowPath + "/../result") == False:
            os.mkdir(self.nowPath + "/../result")
        self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
        self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
        self.check = Check()
        self.logUtil = LogUtil()

    def run(self):
        checkKeyResult = self.check.checkIniKeys()
        #key重复性校验失败
        if checkKeyResult:
            errorKeyPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
            self.logUtil.setKeyLog(errorKeyPath, checkKeyResult)
        #校验成功
        else:
            checkUrlResult = self.check.checkIniUrl()
            #url合法性校验失败
            if checkUrlResult:
                errorUrlPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
                self.logUtil.setUrlLog(errorUrlPath, checkUrlResult)
            #校验成功
            else:
                self.iniObj = IniUtil(self.nowPath + '/../config/url.ini')
                self.iniObjResult = IniUtil(self.resultIniPath)
                cookie = self.getCookie()
                self.doPost(cookie)
                self.setCode()
                self.setHtml()
        print '执行完毕!!'

    def getCookie(self):
        cookie = self.cookieObj.getLoginCookie()
        return cookie

    def doPost(self, cookie):
        #获取配置文件的url
        keysList = []
        urlDict = {}
        keysList = self.iniObj.getKeysBySection('url')
        for key in keysList:
            pageCode = ''
            url = ''
            url = self.iniObj.getValue('url', key)
            urlDict.setdefault(key, url)
            #url = "http://kxyesit.cnsuning.com/"
            try:
                #创建请求的request
                req = urllib2.Request(url)
                handler = urllib2.HTTPCookieProcessor(cookie)
                #利用urllib2的build_opener方法创建一个opener
                openner = urllib2.build_opener(handler)
                responseCode = openner.open(req).getcode()
                #print '页面状态码为:' + str(responseCode)
                pageCode = u'状态码:' + str(responseCode)
                #iniObj.setValue(section='result',key=key,value=pageCode)
                self.iniObjResult.setValue(section='result',
                                           key=key,
                                           value=pageCode)
            except urllib2.URLError, e:
                #print '错误原因:'+e.reason
                reason = e.reason
                pageCode = u'状态码:' + str(e.code) + u';错误原因:' + reason
                #print pageCode
                #iniObj.setValue(section='result',key=key,value=pageCode)
                self.iniObjResult.setValue(section='result',
                                           key=key,
                                           value=pageCode)
示例#4
0
文件: run.py 项目: wliustc/urlControl
class RunCode:
    def __init__(self):
        self.cookieObj = CookieUtil()
        self.nowTile = time.strftime('%Y%m%d%H%M%S')
        self.nowPath = os.getcwd()
        if os.path.exists(self.nowPath + "/../log") == False:
            os.mkdir(self.nowPath + "/../log")
        if os.path.exists(self.nowPath + "/../result") == False:
            os.mkdir(self.nowPath + "/../result")
        self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
        self.errorLogPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
        self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
        self.check = Check()
        self.logUtil = LogUtil()

    def run(self):
        checkKeyResult = self.check.checkIniKeys()
        #key重复性校验失败
        if checkKeyResult:
            self.logUtil.setKeyLog(self.errorLogPath, checkKeyResult)
        #校验成功
        else:
            checkUrlResult = self.check.checkIniUrl()
            #url合法性校验失败
            if checkUrlResult:
                self.logUtil.setUrlLog(self.errorLogPath, checkUrlResult)
            #校验成功
            else:
                self.iniObj = IniUtil(self.nowPath + '/../config/url.ini')
                self.iniObjResult = IniUtil(self.resultIniPath)
                cookie = self.getCookie()
                #解析内容
                self.getContent(cookie)
                #self.doPost(cookie)
                #self.setCode()
                #self.setHtml()
        print '执行完毕!!'

    def getCookie(self):
        cookie = self.cookieObj.getLoginCookie()
        return cookie

    def getContent(self, cookie):
        #获取配置文件的url
        keysList = []
        urlDict = {}
        keysList = self.iniObj.getKeysBySection('url')
        num = 1
        excelUtilObj = ExcelUtil()
        for key in keysList:
            url = self.iniObj.getValue('url', key)
            urlDict.setdefault(key, url)
            try:
                #创建请求的request
                req = urllib2.Request(url)
                handler = urllib2.HTTPCookieProcessor(cookie)
                #利用urllib2的build_opener方法创建一个opener
                openner = urllib2.build_opener(handler)
                response = openner.open(req)

                content = response.read()
                htmlLabel = excelUtilObj.htmlLabel
                worksheet = excelUtilObj.addSheet(key)
                excelUtilObj.setKeys(worksheet)
                self.setExcel(worksheet, num, excelUtilObj, content, htmlLabel)
                num += 1
            except urllib2.URLError, e:
                reason = e.reason
                pageCode = u'状态码:' + str(e.code) + u';错误原因:' + reason
                self.logUtil.setPostErrorLog(self.errorLogPath, url, pageCode)
        excelUtilObj.closeExcel()
示例#5
0
class RunCode:
    def __init__(self):
        self.cookieObj = CookieUtil()
        self.nowTile = time.strftime("%Y%m%d%H%M%S")
        self.nowPath = os.getcwd()
        if os.path.exists(self.nowPath + "/../log") == False:
            os.mkdir(self.nowPath + "/../log")
        if os.path.exists(self.nowPath + "/../result") == False:
            os.mkdir(self.nowPath + "/../result")
        self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
        self.errorLogPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
        self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
        self.check = Check()
        self.logUtil = LogUtil()

    def run(self):
        checkKeyResult = self.check.checkIniKeys()
        # key重复性校验失败
        if checkKeyResult:
            self.logUtil.setKeyLog(self.errorLogPath, checkKeyResult)
        # 校验成功
        else:
            checkUrlResult = self.check.checkIniUrl()
            # url合法性校验失败
            if checkUrlResult:
                self.logUtil.setUrlLog(self.errorLogPath, checkUrlResult)
            # 校验成功
            else:
                self.iniObj = IniUtil(self.nowPath + "/../config/url.ini")
                self.iniObjResult = IniUtil(self.resultIniPath)
                cookie = self.getCookie()
                # 解析内容
                self.getContent(cookie)
                # self.doPost(cookie)
                # self.setCode()
                # self.setHtml()
        print "执行完毕!!"

    def getCookie(self):
        cookie = self.cookieObj.getLoginCookie()
        return cookie

    def getContent(self, cookie):
        # 获取配置文件的url
        keysList = []
        urlDict = {}
        keysList = self.iniObj.getKeysBySection("url")
        num = 1
        excelUtilObj = ExcelUtil()
        for key in keysList:
            url = self.iniObj.getValue("url", key)
            urlDict.setdefault(key, url)
            try:
                # 创建请求的request
                req = urllib2.Request(url)
                handler = urllib2.HTTPCookieProcessor(cookie)
                # 利用urllib2的build_opener方法创建一个opener
                openner = urllib2.build_opener(handler)
                response = openner.open(req)

                content = response.read()
                htmlLabel = excelUtilObj.htmlLabel
                worksheet = excelUtilObj.addSheet(key)
                excelUtilObj.setKeys(worksheet)
                self.setExcel(worksheet, num, excelUtilObj, content, htmlLabel)
                num += 1
            except urllib2.URLError, e:
                reason = e.reason
                pageCode = u"状态码:" + str(e.code) + u";错误原因:" + reason
                self.logUtil.setPostErrorLog(self.errorLogPath, url, pageCode)
        excelUtilObj.closeExcel()
示例#6
0
class RunCode:
    def __init__(self):
        self.cookieObj = CookieUtil()
        self.nowTile = time.strftime("%Y%m%d%H%M%S")
        self.nowPath = os.getcwd()
        if os.path.exists(self.nowPath + "/../log") == False:
            os.mkdir(self.nowPath + "/../log")
        if os.path.exists(self.nowPath + "/../result") == False:
            os.mkdir(self.nowPath + "/../result")
        self.resultIniPath = self.nowPath + "/../log/result_" + self.nowTile + ".ini"
        self.htmlPath = self.nowPath + "/../result/result_" + self.nowTile + ".html"
        self.check = Check()
        self.logUtil = LogUtil()

    def run(self):
        checkKeyResult = self.check.checkIniKeys()
        # key重复性校验失败
        if checkKeyResult:
            errorKeyPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
            self.logUtil.setKeyLog(errorKeyPath, checkKeyResult)
        # 校验成功
        else:
            checkUrlResult = self.check.checkIniUrl()
            # url合法性校验失败
            if checkUrlResult:
                errorUrlPath = self.nowPath + "/../log/result_" + self.nowTile + "_error.ini"
                self.logUtil.setUrlLog(errorUrlPath, checkUrlResult)
            # 校验成功
            else:
                self.iniObj = IniUtil(self.nowPath + "/../config/url.ini")
                self.iniObjResult = IniUtil(self.resultIniPath)
                cookie = self.getCookie()
                self.doPost(cookie)
                self.setCode()
                self.setHtml()
        print "执行完毕!!"

    def getCookie(self):
        cookie = self.cookieObj.getLoginCookie()
        return cookie

    def doPost(self, cookie):
        # 获取配置文件的url
        keysList = []
        urlDict = {}
        keysList = self.iniObj.getKeysBySection("url")
        for key in keysList:
            pageCode = ""
            url = ""
            url = self.iniObj.getValue("url", key)
            urlDict.setdefault(key, url)
            # url = "http://kxyesit.cnsuning.com/"
            try:
                # 创建请求的request
                req = urllib2.Request(url)
                handler = urllib2.HTTPCookieProcessor(cookie)
                # 利用urllib2的build_opener方法创建一个opener
                openner = urllib2.build_opener(handler)
                responseCode = openner.open(req).getcode()
                # print '页面状态码为:' + str(responseCode)
                pageCode = u"状态码:" + str(responseCode)
                # iniObj.setValue(section='result',key=key,value=pageCode)
                self.iniObjResult.setValue(section="result", key=key, value=pageCode)
            except urllib2.URLError, e:
                # print '错误原因:'+e.reason
                reason = e.reason
                pageCode = u"状态码:" + str(e.code) + u";错误原因:" + reason
                # print pageCode
                # iniObj.setValue(section='result',key=key,value=pageCode)
                self.iniObjResult.setValue(section="result", key=key, value=pageCode)