发布于 2014-11-15 11:54:56 | 550 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Python3 官方中文指南,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


本文是一个python实现的利用打码兔和超人打码封装的打码类,打码是利用人工智能大量输入验证码的意思,需要的朋友可以参考下

自封装的打码类, windows下建议用打码兔(调用的官方dll),linux下建议超人打码(http api)


# coding:utf-8
from ctypes import *
import requests
import json
import random
import binascii
from config import config

 

class Dama2():
 """打码兔打码."""
 _username = ''
 _password = ''
 __attrs__ = ['DM', 'username', 'password', 'softuuid', 'timeout']

 def __init__(self):
  self.DM = WinDLL('lib/CrackCaptchaAPI.dll')
  if not self._username:
   Dama2._username = config['dama']['dama2']['username']
   Dama2._password = config['dama']['dama2']['password']
  self.username = c_char_p(self._username)
  self.password = c_char_p(self._password)
  self.softuuid = c_char_p('6fbc06efdc777eee854842572102daec')
  self.timeout = c_ushort(30)

 def recv_byte(self, imgdata, imgtype=42):
  # imgdata = c_void_p(imgdata)
  imgleng = c_uint(len(imgdata))
  imgtype = c_ulong(imgtype)
  res = c_char_p('')

  code = self.DM.D2Buf(self.softuuid, self.username, self.password, imgdata, imgleng, self.timeout, imgtype, res)
  if code > 0:
   return res.value
  return False

 def report_err(self, imgid):
  return False


class Chaoren():
 _username = ''
 _password = ''
 __attrs__ = ['DM', 'username', 'password', 'softuuid', 'timeout']

 def __init__(self):
  if not self._username:
   Chaoren._username = config['dama']['chaoren']['username']
   Chaoren._password = config['dama']['chaoren']['password']

  self.s = requests.Session()
  self.s.encoding = 'utf-8'
  self.s.timeout = 16
  self.data = {
   'username': self.username,
   'password': self.password,
   'softid': '1234',#1234换成自己的
   'imgid': '',
   'imgdata': ''
  }

 def get_left_point(self):
  try:
   r = self.s.post('http://apib.sz789.net:88/GetUserInfo.ashx', self.data)
   return r.json()
  except requests.ConnectionError:
   return self.get_left_point()
  except:
   return False

 def recv_byte(self, imgdata):
  self.data['imgdata'] = binascii.b2a_hex(imgdata).upper()
  try:
   r = self.s.post('http://apib.sz789.net:88/RecvByte.ashx', self.data)
   res = r.json()
   if res[u'info'] == -1:
    self.report_err(res[u'imgid'])  # 识别错误
    return False

   return r.json()[u'result']
  except requests.ConnectionError:
   return self.recv_byte(imgdata)
  except:
   return False

 def report_err(self, imgid):
  self.data['imgid'] = imgid
  if self.data['imgdata']:
   del self.data['imgdata']
  try:
   r = self.s.post('http://apib.sz789.net:88/ReportError.ashx', self.data)
   return r.json()
  except requests.ConnectionError:
   return self.report_err(imgid)
  except:
   return False


class Dama():
 flag = 'dama2'

 def __init__(self):
  if self.flag == 'dama2':
   self.w = Dama2()
  elif self.flag == 'chaoren':
   self.w = Chaoren()
  else:
   self.w = Dama2()  # 默认

 def recv_byte(self, imgdata):
  return self.w.recv_byte(imgdata)

 def report_err(self, imgid):
  return self.w.report_err(imgid)


# test
if __name__ == '__main__':
 pass

"""
username and password 更换为自己的
"""

 



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务