美文网首页
云打码sdk

云打码sdk

作者: sexy_cyber | 来源:发表于2018-06-23 18:31 被阅读69次

极验http://jiyan.c2567.com/
在实战中,将包含改代码的模块导入您的爬虫文件中,调用get_code方法,将验证码的二进制数据传参进去,得到的返回值便是验证码的字符串格式;

官方提供的demo需要改写,才能调用,本代码是改写过的,改写的地方在:

   def post_url(self, url, fields, files=[]):
          # for key in files:
          #     files[key] = open(files[key], 'rb')
          res = requests.post(url, files=files, data=fields)
          return res.text

下面是该写过的完整代码;

import http.client, mimetypes, urllib, json, time, requests


######################################################################

class YDMHttp:
    apiurl = 'http://api.yundama.com/api.php'
    username = ''
    password = ''
    appid = ''
    appkey = ''

    def __init__(self, username, password, appid, appkey):
        self.username = username
        self.password = password
        self.appid = str(appid)
        self.appkey = appkey

    def request(self, fields, files=[]):
        response = self.post_url(self.apiurl, fields, files)
        response = json.loads(response)
        return response

    def balance(self):
        data = {'method': 'balance', 'username': self.username, 'password': self.password, 'appid': self.appid,
                'appkey': self.appkey}
        response = self.request(data)
        if (response):
            if (response['ret'] and response['ret'] < 0):
                return response['ret']
            else:
                return response['balance']
        else:
            return -9001

    def login(self):
        data = {'method': 'login', 'username': self.username, 'password': self.password, 'appid': self.appid,
                'appkey': self.appkey}
        response = self.request(data)
        if (response):
            if (response['ret'] and response['ret'] < 0):
                return response['ret']
            else:
                return response['uid']
        else:
            return -9001

    def upload(self, filename, codetype, timeout):
        data = {'method': 'upload', 'username': self.username, 'password': self.password, 'appid': self.appid,
                'appkey': self.appkey, 'codetype': str(codetype), 'timeout': str(timeout)}
        file = {'file': filename}
        response = self.request(data, file)
        if (response):
            if (response['ret'] and response['ret'] < 0):
                return response['ret']
            else:
                return response['cid']
        else:
            return -9001

    def result(self, cid):
        data = {'method': 'result', 'username': self.username, 'password': self.password, 'appid': self.appid,
                'appkey': self.appkey, 'cid': str(cid)}
        response = self.request(data)
        return response and response['text'] or ''

    def decode(self, filename, codetype, timeout):
        cid = self.upload(filename, codetype, timeout)
        if (cid > 0):
            for i in range(0, timeout):
                result = self.result(cid)
                if (result != ''):
                    return cid, result
                else:
                    time.sleep(1)
            return -3003, ''
        else:
            return cid, ''

    def report(self, cid):
        data = {'method': 'report', 'username': self.username, 'password': self.password, 'appid': self.appid,
                'appkey': self.appkey, 'cid': str(cid), 'flag': '0'}
        response = self.request(data)
        if (response):
            return response['ret']
        else:
            return -9001

    def post_url(self, url, fields, files=[]):
        # for key in files:
        #     files[key] = open(files[key], 'rb')
        res = requests.post(url, files=files, data=fields)
        return res.text


######################################################################

# 用户名
username = 'shixiaolong'

# 密码
password = 'nishijiba'

# 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得!
appid = 5148

# 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得!
appkey = '0f8bb2d83727b737b3662accc'

# 图片文件
filename = 'demo.jpg'

# 验证码类型,# 例:1004表示4位字母数字,不同类型收费不同。请准确填写,否则影响识别率。在此查询所有类型 http://www.yundama.com/price.html
codetype = 3000

# 超时时间,秒
timeout = 60

def get_code(response_content):
    yzm = YDMHttp(username,password,appid,appkey)
    cid,result = yzm.decode(response_content,codetype,timeout)
    return result

if __name__ == '__main__':

    # 检查
    if (username == 'username'):
        print('请设置好相关参数再测试')
    else:
        # 初始化
        yundama = YDMHttp(username, password, appid, appkey)

        # 登陆云打码
        # uid = yundama.login()
        # print('uid: %s' % uid)

        # 查询余额
        # balance = yundama.balance()
        # print('balance: %s' % balance)

        # 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果
        cid, result = yundama.decode(filename, codetype, timeout)
        print('cid: %s, result: %s' % (cid, result))

    ######################################################################

模拟登录云打码案列:

云打码登录竟然使用的是明文密码,而且是get方式,服!

import requests
from diaoyong import get_code

class Denglu:
    def __init__(self):
        self.headers = {
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'
        }
        self.fet = 'http://www.yundama.com/index/captcha'
        self.login = 'http://www.yundama.com/index/login'
        self.session = requests.Session()

    def get_captch(self):
        content = self.session.get(self.fet,headers=self.headers).content
        code = get_code(content)
        print(code)
        return code
    def logins(self):
        code = self.get_captch()
        params = {
            'username':'shixiaolong',
            'password':'nishijiba',
            'utype':1,
            'vcode':code
        }
        content = self.session.get(self.login,headers = self.headers,params=params).content
        print(content)
    def first_page(self):
        url = 'http://www.yundama.com/user'
        response = self.session.get(url,headers=self.headers).text
        print(response)
    def main(self):
        self.logins()
        self.first_page()
if __name__ == '__main__':
    denglu = Denglu()
    denglu.main()


相关文章

网友评论

      本文标题:云打码sdk

      本文链接:https://www.haomeiwen.com/subject/syrdyftx.html