欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python 通過(guò)打碼平臺(tái)實(shí)現(xiàn)驗(yàn)證碼的實(shí)現(xiàn)

 更新時(shí)間:2019年05月13日 10:26:00   作者:shaomine  
這篇文章主要介紹了Python 通過(guò)打碼平臺(tái)實(shí)現(xiàn)驗(yàn)證碼的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

 在爬蟲(chóng)時(shí),經(jīng)常遇到登錄需要驗(yàn)證碼的情況,簡(jiǎn)單的驗(yàn)證碼可以自己解決,復(fù)制的驗(yàn)證碼需要借助機(jī)器學(xué)習(xí),有一定的難度。還有一個(gè)簡(jiǎn)單的方案就是采用付費(fèi)的打碼平臺(tái)。

比如R若快(http://www.ruokuai.com/client),還有云打碼平臺(tái)(http://www.yundama.com/price.html)

下面以R若快為例介紹打碼平臺(tái)的思路:

R若快平臺(tái)需要注冊(cè)兩個(gè)用戶,一個(gè)是普通用戶,一個(gè)開(kāi)發(fā)者用戶,

1、首先驗(yàn)證碼截圖,就是截取網(wǎng)站上登錄頁(yè)面的驗(yàn)證碼圖片并保存到本地

2、調(diào)用打碼平臺(tái)的接口把驗(yàn)證碼圖片發(fā)送到打碼平臺(tái)并獲取到驗(yàn)證碼結(jié)果。

具體代碼如下:

#!/usr/bin/env python
# coding:utf-8

import requests
from hashlib import md5


class RClient(object):

  def __init__(self, username='shaoks123', password='123456', soft_id='113452', soft_key='c0d07d796c8e470c92a126df60d61794'):
    self.username = username
    # self.password = md5(password).hexdigest()
    self.password = md5(password.encode("utf-8")).hexdigest()
    self.soft_id = soft_id
    self.soft_key = soft_key
    self.base_params = {
      'username': self.username,
      'password': self.password,
      'softid': self.soft_id,
      'softkey': self.soft_key,
    }
    self.headers = {
      'Connection': 'Keep-Alive',
      'Expect': '100-continue',
      'User-Agent': 'ben',
    }

  def rk_create(self, im, im_type, timeout=60):
    """
    im: 圖片字節(jié)
    im_type: 題目類型
    """
    params = {
      'typeid': im_type,
      'timeout': timeout,
    }
    params.update(self.base_params)
    files = {'image': ('a.jpg', im)}
    r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
    return r.json()

  def rk_report_error(self, im_id):
    """
    im_id:報(bào)錯(cuò)題目的ID
    """
    params = {
      'id': im_id,
    }
    params.update(self.base_params)
    r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers)
    return r.json()

  def test(self,imagefile,im_type=1030):
    # im = open('E:\python36_crawl\Veriycode\code\code_823.png', 'rb').read()
    im = open(imagefile, 'rb').read()
    result = self.rk_create(im, im_type)
    print(result['Result'])
    return result['Result']


# if __name__ == '__main__':
#   rc = RClient()
#   im = open('E:\python36_crawl\Veriycode\code\code_823.png', 'rb').read()
#   result = rc.rk_create(im, 1030)
#   print(result['Result'])

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論