Beispiel #1
0
 def pre_login(self):
     """
     初始化登陆, 获取viewstate参数 创建验证码图片
     放置在/static/pic/中, 并且返回验证码图片名
     """
     #get __VIEWSTATE
     req = urllib2.Request(self.base_url, headers=self.headers)
     ret = self.opener.open(req)
     page = ret.read()
     com = re.compile(r'name="__VIEWSTATE" value="(.*?)"')
     all = com.findall(page)
     __VIEWSTATE = all[0]
     self.VIEWSTATE = __VIEWSTATE
     #print __VIEWSTATE
     # get CheckCode.aspx
     req = urllib2.Request(self.code_url, headers=self.headers)
     image_content = self.opener.open(req).read()
     import time
     import md5
     time_md5 = md5.md5(str(time.time())).hexdigest()
     #import StringIO
     #filename = StringIO.StringIO()
     image_content = process_image_string(image_content)
     redis_server = init_redis()
     redis_server.hset('checkcode', time_md5,
                       image_content.encode('base64').replace('\n', ''))
     return __VIEWSTATE, time_md5
Beispiel #2
0
 def pre_login(self):
     """
     初始化登陆, 获取viewstate参数 创建验证码图片
     放置在/static/pic/中, 并且返回验证码图片名
     """
     #get __VIEWSTATE
     req = urllib2.Request(self.base_url,headers=self.headers)
     ret = self.opener.open(req)
     page = ret.read()
     com = re.compile(r'name="__VIEWSTATE" value="(.*?)"')
     all = com.findall(page)
     __VIEWSTATE =  all[0]
     self.VIEWSTATE = __VIEWSTATE
     #print __VIEWSTATE
     # get CheckCode.aspx
     req = urllib2.Request(self.code_url,headers = self.headers)
     image_content = self.opener.open(req).read()
     import time
     import md5
     time_md5 = md5.md5(str(time.time())).hexdigest()
     #import StringIO
     #filename = StringIO.StringIO()
     image_content=process_image_string(image_content)
     redis_server = init_redis()
     redis_server.hset('checkcode',time_md5,image_content.encode('base64').replace('\n',''))
     return __VIEWSTATE, time_md5
Beispiel #3
0
def delete_verify_img(time_md5):
    """
    用于删除验证码文件
    """
    try:
        redis_server=init_redis()
        redis_server.hdel('checkcode', time_md5)
    except:
        logger.error('hash delete field %s error'%time_md5)