python复杂的验证码处理(Python 通过打码平台实现验证码的实现)
类别:脚本大全 浏览量:1350
时间:2021-10-02 01:44:32 python复杂的验证码处理
Python 通过打码平台实现验证码的实现在爬虫时,经常遇到登录需要验证码的情况,简单的验证码可以自己解决,复制的验证码需要借助机器学习,有一定的难度。还有一个简单的方案就是采用付费的打码平台。
比如r若快(http://www.ruokuai.com/client),还有云打码平台(http://www.yundama.com/price.html)
下面以r若快为例介绍打码平台的思路:
r若快平台需要注册两个用户,一个是普通用户,一个开发者用户,
1、首先验证码截图,就是截取网站上登录页面的验证码图片并保存到本地
2、调用打码平台的接口把验证码图片发送到打码平台并获取到验证码结果。
具体代码如下:
|
#!/usr/bin/env python # coding:utf-8 import requests from hashlib import md5 class rclient( object ): def __init__( self , username = 'shaoks123' , password = '123456' , soft_id = '113452' , soft_key = 'c0d07d796c8e470c92a126df60d61794' ): self .username = username # self.password = md5(password).hexdigest() 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.jpg" alt="python复杂的验证码处理(Python 通过打码平台实现验证码的实现)" border="0" /> 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 test( self ,imagefile,im_type = 1030 ): # im = open('e:\python36_crawl\veriycode\code\code_823.jpg" alt="python复杂的验证码处理(Python 通过打码平台实现验证码的实现)" border="0" /> im = open (imagefile, 'rb' ).read() result = self .rk_create(im, im_type) print (result[ 'result' ]) return result[ 'result' ] # if __name__ == '__main__': # rc = rclient() # im = open('e:\python36_crawl\veriycode\code\code_823.jpg" alt="python复杂的验证码处理(Python 通过打码平台实现验证码的实现)" border="0" /> # result = rc.rk_create(im, 1030) # print(result['result']) |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://www.cnblogs.com/shaosks/p/9816106.html
您可能感兴趣
- pythonwhile语句的原理(谈谈Python中的while循环语句)
- python协程详解(为什么你还不懂得怎么使用Python协程)
- python交互模式下如何开始运行(python交互界面的退出方法)
- python的静态方法和类方法(深入解析python中的实例方法、类方法和静态方法)
- python删除list的指定元素(Python list列表中删除多个重复元素操作示例)
- pythonselenium接口自动测试(python3+selenium自动化测试框架详解)
- python的基础数据结构有哪些(详解python的四种内置数据结构)
- pythonzipfile的用法(对Python之gzip文件读写的方法详解)
- python3字符串怎么操作(Python3字符串encode与decode的讲解)
- python和mysql实战(由Python编写的MySQL管理工具代码实例)
- pythonlist类型教程(Python List cmp知识点总结)
- python设置按钮(Python按钮的响应事件详解)
- python取当前日期(Python实现根据日期获取当天凌晨时间戳的方法示例)
- python实用教程(Python简直是万能的,这5大主要用途你一定要知道!推荐)
- python实现最简单的游戏(20行python代码的入门级小游戏的详解)
- python选择语句形式判断回文数(Python3实现的回文数判断及罗马数字转整数算法示例)
- 岳云鹏不说相声,改行演员了 网友 快回来说相声(岳云鹏不说相声)
- 乔欣首演古装大女主,颜值演技双在线(乔欣首演古装大女主)
- 于正又推女性古装大剧 杨蓉乔欣演女配,两位女主成 重头戏(于正又推女性古装大剧)
- 乔欣古装女主戏获热度 作为女主,却没吃到红利(乔欣古装女主戏获热度)
- 爱情是什么(爱情是什么最经典的话)
- 乔欣 古装剧中的高颜值(古装剧中的高颜值)
热门推荐
- dedecms迁移data验证码不显示(dedecms织梦上传图片302Error错误的解决方法)
- 云服务器cvm什么意思(什么是云服务器cvm?怎么与普通物理服务器进行)
- dede织梦的后台如何调整和使用(织梦DEDECMS中增加父栏目调用,以及多级支持currentstyle的方法)
- python模块都是自己的语法(详解Python_shutil模块)
- sql分区原理(分区表场景下的 SQL 优化)
- laravel新增数据表(laravel实现上传图片的两种方式小结)
- laravel零基础(基于laravel Request的所有方法详解)
- sql中row的用法(sql server数据库中raiserror函数用法的详细介绍)
- next js上线(Next.js入门使用教程)
- python pyqt 教程(Python+PyQt5实现美剧爬虫可视工具的方法)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9