使用若快服务,python获取图片验证码

上一篇 / 下一篇  2017-08-25 17:49:05 / 个人分类:python

一、创建  RClient.py
#encoding: utf-8
import requests
"""打码api"""

class RClient:

def __init__(self, username, password, soft_id, soft_key):
self.username = username
self.password = password
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': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
}

def create(self, im, im_type, timeout=60):
"""
im: 图片字节
im_type: 题目类型
"""
params = {
'typeid': im_type,
'timeout': timeout,
}
params.update(self.base_params)
files = {'image': ('getcode.png', im)}
r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
return r.json()

def report_error(self, im_id):
"""
im_id:报错题目的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()



二、创建
getVerificationCode.py

#encoding: utf-8
import requests,json
import shutil
import RClient


class getVerificationCode:

def __init__(self):
self.url = "接口地址"
self.headers = {"Content-Type": "application/json"}

def save_verification_code_to_local(self):
session = requests.Session()
resp = session.get(self.url,headers=self.headers,stream=True)
if resp.status_code == 200:
with open("VerificationCode.png",'wb') as f:
shutil.copyfileobj(resp.raw,f)
else:
raise Exception("status_code是{}".format(resp.status_code))

def get_verification_code(self):
getVerificationCode.save_verification_code_to_local(self)
rc = RClient.RClient('若快账号', '若快密码', '若快账号软件ID', '若快软件code')
#rc = RClient.RClient('若快用户账号', '若快用户密码', '86896', '89d840d9954a41019ede4dbea83895d4')
im = open(r'VerificationCode.png', 'rb').read()
result1 = rc.create(im, 3040)
result = result1["Result"]
return result

if __name__ == '__main__':
gc = getVerificationCode()
result = gc.get_verification_code()
print result

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar