验证码破解
- 使用selenium
- 使用打码平台 (推荐)
- 使用机器学习破解
打码平台:超级鹰
超级鹰网址: https://www.chaojiying.com/
- 注册并登录超级鹰账号
- 查看价格体系
- 下载官方文档和代码
chaojiying.py 文件
#!/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 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('niejeff', 'abcdef123456', '898304')
# 本地图片文件路径 来替换 a.jpg
img = open('a.jpg', 'rb').read()
# 1902 验证码类型
print(chaojiying.PostPic(img, 1902))
示例:人人网登录破解
import random
import requests
from chaojiying import Chaojiying_Client
# 1, 保存登录成功后的cookie
# 2, 使用保存的cookie进行登录, 登录后获取个人信息
# url = "http://www.renren.com/548819077/profile"
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
}
# 登录
def login(code):
# 人人网登录接口:
url = "http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=202005945581"
# 参数:
data = {
"email": "18566218080",
"icode": code,
"origURL": "http://www.renren.com/home",
"domain": "renren.com",
"key_id": "1",
"captcha_type": "web_login",
"password": "ba83d3541e9a8c60d769ef6a3a8f249cba83d3541e9a8c60d769ef6a3a8f249c",
"rkey": "ba83d3541e9a8c60d769ef6a3a8f249c",
"f": "",
}
response = session.post(url, data=data, headers=headers)
result = response.content.decode()
print(result)
# 获取验证码,并破解
def get_code():
# 获取验证码接口
url = "http://icode.renren.com/getcode.do?t=web_login&rnd=%s" % str(random.random())
res = session.get(url, headers=headers)
# 下载图片
with open('code.jpg', 'wb') as fp:
fp.write(res.content)
fp.flush()
# 破解验证码
chaojiying = Chaojiying_Client(soft_id='898304')
im = open('code.jpg', 'rb').read()
result = chaojiying.PostPic(im, 2004)['pic_str']
print(result)
return result
# # 人人网个人中心
def get_profile():
url = "http://www.renren.com/548819077/profile"
response2 = session.get(url, headers=headers)
print(response2.text)
if __name__ == '__main__':
session = requests.session()
# 获取验证码
code = get_code()
# 登录
login(code)
# 登录后再访问个人中心
get_profile()