Python 破解验证码
来源:互联网 发布:淘宝的情侣装店铺推荐 编辑:程序博客网 时间:2024/05/18 13:27
(python 2.7)
(所需文件资源地址:http://download.csdn.net/download/tigerking1017/9897375)
示例代码:
# -*- coding:utf8 -*-
from PIL import Image
import hashlib
import time
import os
import math
class VectorCompare:
def magnitude(self,concordance):
total = 0
for word,count in concordance.iteritems():
total += count ** 2
return math.sqrt(total)
def relation(self,concordance1, concordance2):
relevance = 0
topvalue = 0
for word, count in concordance1.iteritems():
if concordance2.has_key(word):
topvalue += count * concordance2[word]
return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2))
def buildvector(im):
d1 = {}
count = 0
for i in im.getdata():
d1[count] = i
count += 1
return d1
v = VectorCompare()
iconset = ['0','1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
imageset = []
for letter in iconset:
for img in os.listdir('./iconset/%s/'%(letter)):
temp = []
if img != "Thumbs.db" and img != ".DS_Store": # windows check...
temp.append(buildvector(Image.open("./iconset/%s/%s"%(letter,img))))
imageset.append({letter:temp})
im = Image.open("captcha.gif")
im2 = Image.new("P",im.size,255)
im.convert("P")
temp = {}
for x in range(im.size[1]):
for y in range(im.size[0]):
pix = im.getpixel((y,x))
temp[pix] = pix
if pix == 220 or pix == 227: # these are the numbers to get
im2.putpixel((y,x),0)
inletter = False
foundletter=False
start = 0
end = 0
letters = []
for y in range(im2.size[0]): # slice across
for x in range(im2.size[1]): # slice down
pix = im2.getpixel((y,x))
if pix != 255:
inletter = True
if foundletter == False and inletter == True:
foundletter = True
start = y
if foundletter == True and inletter == False:
foundletter = False
end = y
letters.append((start,end))
inletter=False
count = 0
for letter in letters:
m = hashlib.md5()
im3 = im2.crop(( letter[0] , 0, letter[1],im2.size[1] ))
guess = []
for image in imageset:
for x,y in image.iteritems():
if len(y) != 0:
guess.append( ( v.relation(y[0],buildvector(im3)),x) )
guess.sort(reverse=True)
print "",guess[0]
count += 1
结果:
- Python 破解验证码
- Python 破解验证码
- Python破解验证码
- 使用Python破解验证码
- 使用Python破解验证码
- Python破解12306图片验证码
- Python入门:PIL之验证码破解
- Python入门:验证码破解(二)
- Python中验证码破解方法详解
- 爬虫实战---python图片验证码破解,PIL和安装
- 图形解锁验证码破解(附Python代码)
- 教你一招 | Python 破解验证码
- 教你一招 | Python 破解验证码
- 第一次破解验证码
- 验证码破解
- 验证码破解方法
- 破解图片验证码
- 验证码的破解
- Java中的byte char String 编码 解码
- Java 多个if 和多个else if 的区别
- Kafka 与 Flume 如何选择
- 三栏布局方法
- Ubuntu如何用anaconda(Python3.6)+tensorflow
- Python 破解验证码
- 从测试的艺术到测试的科学
- 将Flume作为Kafka的Consumer
- 用Google的gflags解析命令行参数
- 生活的源泉
- SPOJ
- kafka的topic多分区的情况,如何保证跨区的消息消费的顺序性
- 资料
- 移动端兼容性处理方案