Example #1
0
    def __unlock_wechat(self, url, resp, session, identify_image_callback=None):
        r_captcha = session.get('https://mp.weixin.qq.com/mp/verifycode?cert=%s' % (time.time() * 1000))
        if not r_captcha.ok:
            raise SogouCrawlerRequestsException('SogouAPI unlock_history get img failed', resp)

        r_unlock = self.unlock_wechat_callback(url, session, resp, r_captcha.content, identify_image_callback)

        if r_unlock['ret'] != 0:
            raise SogouCrawlerVerificationCodeException(
                '[SogouAPI identify image] code: %s, msg: %s, cookie_count: %s' % (
                    r_unlock.get('ret'), r_unlock.get('errmsg'), r_unlock.get('cookie_count')))
Example #2
0
    def __unlock_sogou(self, url, resp, session, identify_image_callback=None):

        millis = int(round(time.time() * 1000))
        r_captcha = session.get('http://weixin.sogou.com/antispider/util/seccode.php?tc=%s' % millis)
        if not r_captcha.ok:
            raise SogouCrawlerRequestsException('SogouAPI get verfication code faild:', resp)

        r_unlock = self.unlock_sogou_callback(url, session, resp, r_captcha.content, identify_image_callback)

        if r_unlock['code'] != 0:
            raise SogouCrawlerVerificationCodeException(
                '[SogouAPI identify image] code: %s, msg: %s' % (r_unlock.get('code'),
                                                                 r_unlock.get('msg')))
Example #3
0
    def unlock_wechat_callback(self, url, req, resp, img, identify_image_callback):
        unlock_url = 'https://mp.weixin.qq.com/mp/verifycode'
        data = {
            'cert': time.time() * 1000,
            'input': identify_image_callback(img)
        }
        headers = {
            'Host': 'mp.weixin.qq.com',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        }
        r_unlock = req.post(unlock_url, data, headers=headers)
        if not r_unlock.ok:
            raise SogouCrawlerVerificationCodeException(
                'unlock[%s] failed: %s[%s]' % (unlock_url, r_unlock.text, r_unlock.status_code))

        return r_unlock.json()
Example #4
0
    def unlock_sogou_callback(self, url, req, resp, img, identify_image_callback):
        url_quote = url.split('weixin.sogou.com/')[-1]

        unlock_url = 'http://weixin.sogou.com/antispider/thank.php'
        data = {
            'c': identify_image_callback(img),
            'r': '%2F' + url_quote,
            'v': 5
        }
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Referer': 'http://weixin.sogou.com/antispider/?from=%2f' + url_quote
        }
        r_unlock = req.post(unlock_url, data, headers=headers)
        if not r_unlock.ok:
            raise SogouCrawlerVerificationCodeException(
                'url: %s unlock[%s] failed: %s' % (unlock_url, r_unlock.text, r_unlock.status_code))

        return r_unlock.json()