Пример #1
0
   def qiangkeStep2(self, class_name, ext_params={}):
      
      gx_url = self.__info['base_url'] + 'xf_xsqxxxk.aspx?xh=' + self.__info['xuehao']
      param = {}
      param['TextBox1'] = class_name
      param['Button2'] = '确定'
      
      content = self.post(gx_url, param)
      
      if content == False:
         raise sdutException(202 ,u'正方错误!!!查找课表失败!!!')
      preg = u'<legend>可选课程<\/legend><table class="datelist " cellspacing="0" cellpadding="3" border="0" id="kcmcGrid" width="100%">[\s\S]*?<\/table>'
      
      could_select = re.search(preg, content, re.I)
      
      class_time = ''
      class_where = ''

      if ext_params.get('class_time'):
         class_time = ext_params.get('class_time')
         class_time = class_time.decode('utf-8')
      if ext_params.get('class_where'):
         class_where = ext_params.get('class_where')
         class_where = class_where.decode('utf-8')
      class_name = class_name.decode('utf-8')
      preg2 = u'<td>[\s\S]{0,200}(<input[\s\S]{0,200}name="([^"]{0,100}:xk)" \/>[\s\S]{0,400}<a.{0,300}>'+class_name+'.{1,100}<\/a>.*'+class_time+'.*'+class_where+')'
      result2 = re.search(preg2, could_select.group(0), re.I)
      
      if result2:

         return result2.group(2)
      else:
         raise sdutException(403 ,u'正方提示:找不到课程')
Пример #2
0
 def getKB(self, param={}):
    if self.__cookie == '':
       raise sdutException(101 , u'请先登录再获取课表')
    else:        
       kb_url = self.__info['base_url'] + 'xskbcx.aspx?xh=' + self.__info['xuehao']
       content = self.get(kb_url)
       if len(param) > 0:
          content = self.post(kb_url, param)
       return content
Пример #3
0
   def __checkResonse(self, content):
      try:

         if content.find(u'Location: /logout.aspx') >= 0 or content.find(u'Location: /default2.aspx') >= 0 or content.find(u'请重新登陆,如无法解决,请稍后再试')>=0:
            raise Exception(u'正方发生错误!!!请重新登录!!!!')
         if content.find(u'<title>ERROR - 出错啦!</title>') >= 0 :
            raise Exception(u'正方提示:ERROR - 出错啦!!!')         
      except Exception as e:
         self.__cookie = ''
         msg = str(e)
         raise sdutException(101, msg)
      if content.find(u'三秒防刷') >=0:
         raise sdutException(201 ,u'正方提示:三秒防刷!!!')
      if content.find(u'<html><head><title>Object moved</title></head><body>') >=0:
         if self.__has_error_time > self.__max_error_time:
            self.__uhas_error_time = 0
            self.__cookie = ''
         raise sdutException(202 ,u'正方错误!!!Object moved')
Пример #4
0
   def qiangkeStep3(self, class_code):
      param = {}
      gx_url = self.__info['base_url'] + 'xf_xsqxxxk.aspx?xh=' + self.__info['xuehao']
      param[class_code] = 'on'
      param['Button1'] = '提交'

      content = self.post(gx_url, param)

      preg = '<script language=\'javascript\'>alert\(\'([^)]*)\'\);<\/script>'
      error_alert = re.search(preg, content, re.I)
      if error_alert:
         raise sdutException(405, error_alert.group(1))
      else:
         preg = u'(<tr class="datelisthead">[\s]*<td>课程名称<\/td><td>教师姓名<\/td><td>学分<\/td><td>周学时<\/td><td>起始结束周<\/td><td>校区<\/td><td>上课时间<\/td><td>上课地点<\/td><td>教材<\/td><td>课程归属<\/td><td>课程性质<\/td><td>校区代码<\/td><td>退选<\/td>[\s]*<\/tr>[\s]*([\s\S]*?)<\/table>)'
         result = re.search(preg, content, re.I).group(0)
         return result