def item_completed(self, results, item, info): if self.IMAGES_RESULT_FIELD in item.fields: item[self.IMAGES_RESULT_FIELD] = [x for ok, x in results if ok] log.msg('got verify code result %s' % json.dumps(obj=item[self.IMAGES_RESULT_FIELD], ensure_ascii=False, indent=4)) path = settings.IMAGES_STORE + '/' + item[self.IMAGES_RESULT_FIELD][0]['path'] code = None while not code: code = dama.dama(path) code = str(code) log.msg('got code %s' % code) RedisHelper.get_redis_conn().set(item['key'], code) raise DropItem('drop it.')
def start_login(self, resp): path = "%s/vc_%d.jpg" % (self.res_dir, time.time()) with open(path, "wb") as f: f.write(resp.body) rand = None while not rand: rand = dama.dama(path) time.sleep(3) self.log('%s got verify code %s' % (self.name, rand), log.INFO) return [FormRequest(url=self.login_url, formdata={ 'login' : self.login_username, 'passwd' : self.login_password, 'rand' : rand }, callback=self.parse_login, meta=resp.meta)]