Example #1
0
 def __init__(self):
     self.fileName = '../config/cookie.txt'
     self.iniObj = IniUtil('../config/config.ini')
     self.loginUrl = self.iniObj.getValue('loginUrl', 'url')
     #self.loginUrl = 'https://passport.suning.com/ids/login?method=GET&loginTheme=b2c'
     self.vCodeName = "../config/vcode.png"
     #MozillaCookieJar提供可读写操作的cookie文件,存储cookie对象
     self.cookiejar = cookielib.MozillaCookieJar(self.fileName)
Example #2
0
 def getHtmlLabel(self):
     iniObj = IniUtil(self.configIniPath)
     sections = iniObj.getSections()
     list = []
     for sec in sections:
         tmpList = iniObj.getKeysBySection(sec)
         list.extend(tmpList)
     return list
Example #3
0
 def checkIniUrl(self):
     iniObj = IniUtil(self.iniPath)
     keys = iniObj.getKeysBySection('url')
     for key in keys:
         url = iniObj.getValue('url', key)
         if self.checkUrl(url) == False:
             self.falseUrl.append(url)
     return self.falseUrl
Example #4
0
 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 '执行完毕!!'
Example #5
0
 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 '执行完毕!!'
Example #6
0
 def __init__(self, filePath):
     self.iniObj = IniUtil(filePath)
Example #7
0
# -*- coding:utf-8 -*-
import urllib2
from iniUtil import IniUtil
from cookieUtil import CookieUtil

cookieObj = CookieUtil()
iniObj = IniUtil('../config/url.ini')
cookie = cookieObj.getLoginCookie()
#获取配置文件的url
keysList = []
urlDict = {}
keysList = iniObj.getKeysBySection('url')
for key in keysList:
    pageCode = ''
    url = ''
    url = 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=u'状态码', key=key, value=pageCode)
    except urllib2.URLError, e:
        #print '错误原因:'+e.reason
        reason = e.reason
Example #8
0
 def __init__(self, resultIniPath, htmlPath):
     html = open(htmlPath, 'w+')
     #iniObj = IniUtil('../log/result.ini')
     iniObj = IniUtil(resultIniPath)
     strFirst = '''
     <html>
      <head>
       <meta charset="utf-8" />
       <title>状态码</title>
      </head>
      <body>
       <table align="center" width="80%" border="1">
        <tbody>
         <tr>
          <td colspan="3" align="center">
           <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
           <div id="codeImg" style="height:300px;width:400px;"></div> </td>
         </tr>
         <tr>
          <td colspan="3" align="center">
           <table width="100%" border="1" cellspacing="0" cellpadding="0" class="sp-order-table">
            <thead>
             <tr bgcolor="#CECEFF">
              <td>标题</td>
              <td>URL</td>
              <td>状态码</td>
              <td>结果</td>
             </tr>
            </thead>
     '''
     colorRed = "style='color:#FF0000'"
     colorGreen = "style='color:#00FF7F'"
     titleList = iniObj.getKeysBySection('result')
     strTbody = '<tbody>'
     codeStr = ''
     code = ''
     reasonStr = ''
     reason = ''
     colorFlag = ''
     for title in titleList:
         codeStr = ''
         reasonStr = ''
         code_reason_Str = iniObj.getValue('result', title)
         if ";" in code_reason_Str:
             codeStr = code_reason_Str.split(";")[0]
             #code = codeStr.split(":")[1]
             reasonStr = code_reason_Str.split(";")[1]
             #reason = reasonStr.split(":")[1]
             colorFlag = colorRed
         else:
             reasonStr = '通过'
             codeStr = code_reason_Str.split(";")[0]
             #code = codeStr.split(":")[1]
             colorFlag = colorGreen
         strTbody += "<tr>"
         strTbody += "<td>" + title + "</td>"
         strTbody += "<td>" + iniObj.getValue('result', title) + "</td>"
         strTbody += "<td>" + codeStr + "</td>"
         strTbody += "<td " + colorFlag + ">" + reasonStr + "</td>"
         strTbody += "</tr>"
     strTbody += '</tbody>'
     strSecond = '''
           </table>
           </td>
         </tr>
        </tbody>
       </table>
       <!-- ECharts单文件引入 -->
       <script src="../config/echarts.common.min.js"></script>
       <style>
         body{ text-align:center}
         .sp-order-table {
             clear: both;
             border: 1px solid #ebebeb;
             margin-top: 20px;
         }
       </style>
       <script type="text/javascript">
         // 基于准备好的dom,初始化echarts图表
         var myChart = echarts.init(document.getElementById('codeImg'));
         var option = {
         //标题
         title : {
             text: '状态码',
             //subtext: '纯属虚构',
             x:'center'
         },
     '''
     dataName = '['
     data = ''
     strThird = ''
     codeList = iniObj.getKeysBySection('code')
     for codeName in codeList:
         dataName += "'" + codeName + "',"
         num = iniObj.getValue('code', codeName)
         data += "{value:" + num + ", name:'" + codeName + "'},"
     dataName = dataName[:-1] + ']'
     strThird = '''
         //左侧竖直列
         legend: {
             orient : 'vertical',
             x : 'left',
             data:''' + dataName + '''
         },
         //饼图值
         series : [
             {
                 name:'状态码',
                 type:'pie',
                 radius : '55%',
                 center: ['50%', '60%'],
                 data:[''' + data[:-1] + '''
                 ]
             }
         ]
     };
     '''
     strFour = '''
         // 为echarts对象加载数据
         myChart.setOption(option);
       </script>
      </body>
     </html>
     '''
     strHtml = strFirst + strTbody + strSecond + strThird + strFour
     html.write(strHtml)
     html.close()