selenium验证码识别,超级鹰干超级鹰

from selenium.webdriver import Edge
from selenium.webdriver.common.by import By
# 在这里导入浏览器设置相关的类
from selenium.webdriver.edge.options import Options
# 导入超级鹰的类
from chaojiying import Chaojiying_Client

# 登录超级鹰账号
chaojiying = Chaojiying_Client('账号', '密码', '软件ID:')

# 如果不进行这步操作,登录成功后会自动关闭
# 这里!!!!实现不关闭的重点
edge_options = Options()
# 修改谷歌浏览器测试选项中的参数,使得打开后的浏览器不会自动关闭
edge_options.add_experimental_option("detach", True)
web = Edge(options=edge_options)

web.get("http://www.chaojiying.com/user/login/")
# 验证码输出  screenshot_as_png 屏幕截屏
img = web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png
# 验证码识别
dic = chaojiying.PostPic(img, 3004)
captcha = dic['pic_str']
print(captcha)

# 输入账号,密码,验证码
web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys('账号')
web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys('密码')
web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(captcha)

# 点击登录
web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click()

 

超级鹰验证码识别类

# 超级鹰类

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

import requests
from hashlib import md5


class Chaojiying_Client(object):

    def __init__(self, username, password, soft_id):
        self.username = username
        password = password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    def PostPic(self, im, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files,
                          headers=self.headers)
        return r.json()

    def PostPic_base64(self, base64_str, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
            'file_base64': base64_str
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, headers=self.headers)
        return r.json()

    def ReportError(self, im_id):
        """
        im_id:报错题目的图片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
        return r.json()


if __name__ == '__main__':
    # 用户中心>>软件ID 生成一个替换 96001
    chaojiying = Chaojiying_Client('账号', '密码', '用户id')
    # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
    im = open('a.jpg', 'rb').read()
    # 1902 验证码类型  官方网站>>价格体系 3.4+版 print 后要加()
    print(chaojiying.PostPic(im, 1104))
    # print chaojiying.PostPic(base64_str, 1902)  #此处为传入 base64代码

 

posted @ 2023-03-07 10:29  0x1e61  阅读(81)  评论(0编辑  收藏  举报