python识别验证码并自动登录_Python 实现全自动登录(真正的全自动,自动识别验证码)...

#!/usr/bin/env python

# coding:utf-8

from selenium import webdriver

from PIL import Image

import requests

from hashlib import md5

import time

class RClient(object):

def __init__(self, username, password, soft_id, soft_key):

self.username = username

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: 图片字节

im_type: 题目类型

"""

params = {

'typeid': im_type,

'timeout': timeout,

}

params.update(self.base_params)

files = {'image': ('a.png', 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:报错题目的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 get_code(im_file):

rc = RClient('账号', '密码', '94522', '62c235939b7240879453f31603733fd6')

im_source = open(im_file, "rb").read()

print(rc.rk_create(im_source, 3040))

if __name__ == '__main__':

wbe = webdriver.PhantomJS()

wbe.get("https://www.dajiang365.com/login/index.html")

time.sleep(2)

wbe.save_screenshot("das.png")

element = wbe.find_element_by_xpath('//*[@id="entry_name"]/p[3]/img')

left = element.location['x']

top = element.location['y']

right = element.location['x'] + element.size['width']

bottom = element.location['y'] + element.size['height']

im = Image.open(r'das.png')

im = im.crop((left, top, right, bottom))

im.save('a.png')

time.sleep(2)

get_code("a.png")

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值