Python爬虫之超级鹰验证码应用

作者:XWenXiang 时间:2021-04-08 08:22:20 

超级鹰平台

验证码的破解可以有以下方式:

  • 简单的数字字母组合可以使用图像识别(python 现成模块),成功率不高

  • 使用第三方打码平台(破解验证码平台),花钱,把验证码图片给它,返回识别完的结果

第三方平台有超级鹰等等。

基础使用

在其官网注册账号后,绑定微信会提供免费的1000题分,可用于验证码识别

创建开发者账号,并且注册一个软件

Python爬虫之超级鹰验证码应用

下载 python demo

Python爬虫之超级鹰验证码应用

基础使用

下载的demo是使用python2编写的,需要简单修改

import requests
from hashlib import md5
class ChaojiyingClient(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__':
   chaojiying = ChaojiyingClient('超级鹰用户名', '超级鹰用户名的密码', '96001')  # 用户中心>>软件ID 生成一个替换 96001
   im = open('a.jpg', 'rb').read()  # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
   print(chaojiying.PostPic(im, 1902))  # 1902 验证码类型  官方网站>>价格体系 3.4+版 print 后要加()
   # print chaojiying.PostPic(base64_str, 1902)  #此处为传入 base64代码

Python爬虫之超级鹰验证码应用

剪切验证码

实际使用的时候验证码是不固定的,需要剪切下来使用,需要使用 pillow 模块

截图需要注意分辨率

from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image
from selenium.webdriver.chrome.options import Options
from chaojiying import chaojiying_Python
chrome_options = Options()
chrome_options.add_argument('window-size=1920x1080')  # 指定浏览器分辨率
chrome_options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
# chrome_options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
chrome_options.add_argument('--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
# chrome = webdriver.Chrome(executable_path='../chromedriver.exe')
chrome = webdriver.Chrome(executable_path='../chromedriver.exe', options=chrome_options)
chrome.implicitly_wait(10)
chrome.maximize_window()
try:
   chrome.get('http://www.aa7a.cn/user.php?')
   username = chrome.find_element(By.ID, 'username')
   password = chrome.find_element(By.ID, 'password')
   captcha = chrome.find_element(By.ID, 'captcha')
   # 保存大图
   chrome.save_screenshot('main.png')
   img = chrome.find_element(By.ID, 'login_img_checkcode')
   img_location = img.location
   img_size = img.size
   # 使用pillow扣除大图中的验证码
   img_tu = (
       int(img_location['x']),
       int(img_location['y']),
       int(img_location['x'] + img_size['width']),
       int(img_location['y'] + img_size['height']),
   )
   # 打开页面大图
   im = Image.open('./main.png')
   # 剪切验证码图片
   fram = im.crop(img_tu)
   # 保存验证码图片
   fram.save('code.png')
   # 打开验证码图片
   code_img = open('code.png', 'rb').read()
   # 调用超级鹰识别
   res = chaojiying_Python.chaojiying.PostPic(code_img, 1902)
   code = res.get('pic_str')
   username.send_keys('username')
   password.send_keys('123')
   captcha.send_keys(code)
   print(code)
except Exception as e:
   print(e)
finally:
   chrome.quit()

Python爬虫之超级鹰验证码应用

来源:https://blog.csdn.net/m0_58987515/article/details/126144036

标签:Python,验证码,超级鹰
0
投稿

猜你喜欢

  • 个人经验总结:完全卸载MySQL数据库5.0

    2009-01-04 13:07:00
  • asp代码WinHttp.WinHttpRequest.5.1使用例子

    2010-03-11 21:28:00
  • PHP设计模式中的命令模式

    2023-05-27 21:13:43
  • 构建成功web应用的十项黄金法则

    2010-09-17 19:11:00
  • asp文章干扰码实现方法

    2007-08-19 18:07:00
  • Python OpenCV实现3种滤镜效果实例

    2021-06-04 10:20:27
  • Python中使用matplotlib模块errorbar函数绘制误差棒图实例代码

    2022-11-09 17:01:42
  • Python读取txt文件数据的方法(用于接口自动化参数化数据)

    2023-12-28 03:21:52
  • python使用matplotlib库生成随机漫步图

    2021-03-01 15:11:37
  • Flask 让jsonify返回的json串支持中文显示的方法

    2022-01-23 04:20:31
  • ORACLE LATERAL-SQL-INJECTION 个人见解

    2009-03-04 10:34:00
  • python编写计算器功能

    2022-10-29 14:07:33
  • Python二进制数据结构Struct的具体使用

    2022-07-10 00:01:59
  • Python Cookie 读取和保存方法

    2021-01-21 15:57:51
  • Flask模拟实现CSRF攻击的方法

    2023-11-18 16:21:39
  • numpy中hstack vstack stack concatenate函数示例详解

    2023-02-22 19:39:06
  • 浅谈Python2.6和Python3.0中八进制数字表示的区别

    2023-04-22 23:56:42
  • Python实现简单扫雷游戏

    2022-03-27 15:05:23
  • 下一代web:浏览器存储支持

    2008-06-11 11:50:00
  • DW MX新功能试用:嵌套模板

    2008-02-03 11:35:00
  • asp之家 网络编程 m.aspxhome.com