Ejemplo n.º 1
0
 def resolve_with_lianzhong(img, test=False):
     server = LianzhongCaptcha()
     points = server.point_check()
     if points <= 0:
         print 'there are no more points'
         return
     if test:
         print 'There are %d points remaining' % points
     captcha = server.resolve(img)
     return captcha
Ejemplo n.º 2
0
    def resolve_captcha(self, img):
        server = LianzhongCaptcha()
        points = server.point_check()
        if points <= 0:
            print 'there are no more points'
            return
        print 'There are %d points remaining' % points

        captcha = server.resolve(img)
        if self.test_mode:
            print 'resolved captcha', captcha
        return captcha
Ejemplo n.º 3
0
class HrImager(object):
    def __init__(self):
        self.lianzhongC = LianzhongCaptcha()

    def get_code(self, osr, codeurl):
        headers = {'Referer': HrConfig.LOGIN_REFER}
        con = osr.request_url(codeurl, headers=headers)
        f = StringIO.StringIO()
        f.write(con.content)
        f.seek(0)
        self.code = self.lianzhongC.resolve(f)
        return self.code
Ejemplo n.º 4
0
class LPImager(object):
    def __init__(self):
        self.lianzhongC = LianzhongCaptcha()

    def get_code(self, osr):
        headers={'Referer': Config.LOGIN_URL}
        con = osr.request_url('https://passport.liepin.com/captcha/randomcode/?' + str(random.random()), headers=headers)
        f = StringIO.StringIO()
        f.write(con.content)
        f.seek(0)
        self.code = self.lianzhongC.resolve(f)
        return self.code

    ##type=1, 企业账号情况
    ## type=2, 猎头账号情况
    def get_user_valid_code(self, osr, url, type):

        headers = {

            'Upgrade-Insecure-Requests':'1'

        }
        con = osr.request_url('https://www.liepin.com/image/randomcode4ValidationUser/?time=%d' % int(time.time()*1000), headers=headers)
        f = StringIO.StringIO()
        f.write(con.content)
        f.seek(0)
        self.code = self.lianzhongC.resolve(f)
        return self.code

    def find_codeurl(self, content):
        doc = html.fromstring(content)
        img = doc.xpath('//img')
        if img:
            return "http://www.liepin.com" + img[0]

        return None
Ejemplo n.º 5
0
 def check_image(self, con):
     key = self.chklock.trylock()
     if key:
         try:
             lz = LianzhongCaptcha()
             if not lz.point_check():
                 Log.error("no image resolver")
                 raise SpiderErrors.FatalError("no image resovler")
             hf = spider.util.htmlfind(con.text, "<form", 0)
             a, b = hf.process_form()
             while True:
                 image = self.request_url(
                     "https://passport.liepin.com/captcha/randomcode/?time=%d"
                     % int(time.time() * 1000))
                 vcode = a["verifycode"] = lz.resolve(image.content, 4, 4)
                 if not vcode:
                     continue
                 vcodecc = re.search("verifycode=([0-9a-f]+)",
                                     image.headers)
                 headers = {
                     'Referer': con.request.url,
                     'X-Requested-With': 'XMLHttpRequest',
                     "Cookie": "verifycode=%s" % vcodecc.group(1)
                 }
                 con1 = self.request_url(
                     "https://passport.liepin.com/inspect/validate.json",
                     headers=headers,
                     data=a)
                 if con1.text[0:1] == '{' and u'验证码填写有误,请重新填写' in con1.text:
                     pass
                 else:
                     break
         finally:
             self.chklock.unlock(key)
     else:
         time.sleep(10)
Ejemplo n.º 6
0
 def __init__(self):
     self.lianzhongC = LianzhongCaptcha()
Ejemplo n.º 7
0
 def resolve_image(self, rv, imgcode, uin, appid):
     u1p = {
         "aid": appid,
         "uin": uin,
         "clientype": "2",
         "pt_style": "33",
         "cap_cd": imgcode,
         "rand": str(random.random())
     }
     con1 = self.request_url("https://ssl.captcha.qq.com/cap_union_show",
                             params=u1p)
     vsig = spider.util.chained_regex(con1.text,
                                      r'var\s+g_vsig\s*=\s*"(.*?)"')[0]
     #con2 = self.request_url("https://ssl.captcha.qq.com/cap_union_getsig_new", params=u1p)
     #con2j = json.loads(con2.text)
     #vsig = con2j['vsig']
     u3p = {
         "uin": uin,
         "rand": str(random.random()),
         "cap_cd": imgcode,
         "clientype": "2",
         "aid": appid,
         "sig": vsig,
         "pt_style": "33"
     }
     con3 = self.request_url("https://ssl.captcha.qq.com/getimgbysig",
                             params=u3p)
     img_start_time = int(time.time())
     lc = LianzhongCaptcha()
     if hasattr(self, 'lianzhongcheck') is False:
         self.lianzhongcheck = False
     if self.lianzhongcheck is False:
         with open('xx.jpg', 'wb') as fi:
             fi.write(con3.content)
         sys.stderr.write("input image code: ")
         uimgcode = sys.stdin.readline().strip()
     else:
         pc = lc.point_check()
         print '========begin lianzhong img input with points:', pc
         if pc > 0:
             uimgcode = lc.resolve(con3.content)
             print "image codde is:", uimgcode
         else:
             sys.stderr.write("cant resolve image by lianzhong.\n")
             time.sleep(3)
             return False
     chks = {
         "uin": uin,
         "rand": str(random.random()),
         str(random.random()): "",
         "capclass": "0",
         "cap_cd": imgcode,
         "sig": vsig,
         "clientype": "2",
         "aid": appid,
         "ans": uimgcode,
         "collect": self.build_trace_data(img_start_time),
         "pt_style": "33"
     }
     con4 = self.request_url(
         "https://ssl.captcha.qq.com/cap_union_verify_new", params=chks)
     sys.stderr.write("verify imgcode %s : %s\n" % (uimgcode, con4.text))
     j4 = json.loads(con4.text)
     if int(j4.get('errorCode', '-1')) == 0:
         rv.update(j4)
         return True
     else:
         if lc:
             sys.stderr.write(
                 "verify imagecode %s : mark lianzhong error!\n" % uimgcode)
             lc.mark_last_error()
         return False