前言
验证码?我也能破解?
关于验证码的介绍就不多说了,各种各样的验证码在人们生活中时不时就会冒出来,身为学生日常接触最多的就是教务处系统的验证码了,比如如下的验证码:
比如数字六的矩阵
num_6=[
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,1,0,0,0,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,0,0,
0,0,0,1,1,1,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,0,0,0,0,0,
0,0,1,1,0,0,0,0,0,0,0,0,0,
0,0,1,1,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,0,0,0,0,
0,1,1,0,0,0,0,1,1,1,0,0,0,
0,1,1,0,0,0,0,0,1,1,0,0,0,
0,1,1,0,0,0,0,0,1,1,0,0,0,
0,1,1,1,0,0,0,1,1,1,0,0,0,
0,0,1,1,1,1,1,1,1,0,0,0,0,
0,0,0,1,1,1,1,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
]
远远望过去,眯着眼睛还是能分辨出来的。
因为验证码十分规整,每个数字所在的位置都是固定的,所以并不需要涉及什么机器学习的算法,只是简单的进行一下矩阵的比对就可以了,在所有的实现做好的矩阵中找到相似度最高的矩阵就可以了,在这里的比对方法多种多样,反正数据简单能正确识别出来就好。
至此,咱们的验证码识别工作就结束了。
这次进行的验证码识别主要采用python的pil进行图片操作,模拟登陆自动填写验证码的全部代码请看这里:
示例代码
# -*- coding: utf-8 -*
import sys
reload(sys)
sys.setdefaultencoding( “utf-8” )
import re
import requests
import io
import os
import json
from pil import image
from pil import imageenhance
from bs4 import beautifulsoup
import mdata
class student:
def __init__(self, user,password):
self.user = str(user)
self.password = str(password)
self.s = requests.session()
def login(self):
url = “http://202.118.31.197/actionlogon.appprocess?mode=4”
res = self.s.get(url).text
imageurl = ‘http://202.118.31.197/’+re.findall(‘