zoukankan      html  css  js  c++  java
  • 若快打码平台python开发文档修改版

    一、打码的作用

      在进行爬虫过程中,部分网站的登录验证码是比较简单的,例如四个英文数字随机组合而成的验证码,有的是全数字随机组成的验证码,有的是全中文随机组成的验证码。为了爬虫进行自动化,需要解决自动登录的问题,而验证码问题成了第一道坎。起初想到用百度AI的图像识别技术进行识别,但识别结果却很差,最后还是想起用打码平台来解决吧。打码平台的识别率算起来还是比较高的,所有花钱还是能办事的。

    二、若快打码原python开发文档

      在若快官网下载的python文档我觉得写得过于臃肿,但开发思想(面向对象编程)还是值得肯定的,但有时候能简即简,毕竟我们只是为了获取识别结果而已。原开发文档代码如下:

     1 #!/usr/bin/env python
     2 # coding:utf-8
     3 
     4 import requests
     5 from hashlib import md5
     6 
     7 
     8 class RClient(object):
     9 
    10     def __init__(self, username, password, soft_id, soft_key):
    11         self.username = username
    12         self.password = md5(password.encode('utf-8')).hexdigest()
    13         self.soft_id = soft_id
    14         self.soft_key = soft_key
    15         self.base_params = {
    16             'username': self.username,
    17             'password': self.password,
    18             'softid': self.soft_id,
    19             'softkey': self.soft_key,
    20         }
    21         self.headers = {
    22             'Connection': 'Keep-Alive',
    23             'Expect': '100-continue',
    24             'User-Agent': 'ben',
    25         }
    26 
    27     def rk_create(self, im, im_type, timeout=60):
    28         """
    29         im: 图片字节
    30         im_type: 题目类型
    31         """
    32         params = {
    33             'typeid': im_type,
    34             'timeout': timeout,
    35         }
    36         params.update(self.base_params)
    37         files = {'image': ('a.jpg', im)}
    38         r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
    39         return r.json()
    40 
    41     def rk_report_error(self, im_id):
    42         """
    43         im_id:报错题目的ID
    44         """
    45         params = {
    46             'id': im_id,
    47         }
    48         params.update(self.base_params)
    49         r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers)
    50         return r.json()
    51 
    52 
    53 if __name__ == '__main__':
    54     rc = RClient('普通用户账号', '普通用户账号密码', '软件ID', '软件key')
    55     im = open('a.jpg', 'rb').read()
    56     print(rc.rk_create(im, 3040)['Result'])

    下载他们的开发文档代码后研读了一遍发现还有错误的,就是在进行用户密码md5加密时候竟然没有二进制化!!!罢了,可能是压根就没测这文档,自己弄吧还是。。。

    三、官方文档修改版

      官方文档写的真是太难受了,最后还是修改一下,代码如下:

    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import requests
    from hashlib import md5
    
    
    def get_code_text(file_name, img_type):
        """
        获取验证码
        :param file_name: 验证码本地图片的路径
        :param img_type: 要识别的验证码类型
        :return: 识别后的验证码
        """
    
        headers = {
            'Connection': 'Keep-Alive',
            'Expect': '100-continue',
            'User-Agent': 'ben',
        }
        params = {
            'username': '普通用户账号',
            'password': md5('普通用户账号密码'.encode('utf8')).hexdigest(),
            'softid': '120055',
            'softkey': '6b4977398eb94ddeb0f733e18982042f',
            'typeid': img_type,
            'timeout': 30,
        }
        with open(file_name, 'rb') as f:
            content = f.read()
        files = {'image': (file_name, content)}
        res = requests.post('http://api.ruokuai.com/create.json', data=params,
                            files=files, headers=headers)
        return res.json()['Result']
  • 相关阅读:
    hdu 4332 Constructing Chimney 夜
    poj 2449 Remmarguts' Date 夜
    poj 2728 Desert King 夜
    poj 1639 Picnic Planning 夜
    poj 1125 Stockbroker Grapevine 夜
    poj 3621 Sightseeing Cows 夜
    hdu 4333 Revolving Digits 夜
    hdu 4345 Permutation 夜
    hdu 1874 通畅工程续 夜
    es6(二)
  • 原文地址:https://www.cnblogs.com/zepc007/p/10247916.html
Copyright © 2011-2022 走看看