以易码网站的注册界面为例
python版本:2.7
所需要的代码库:PIL,selenium,pytesser
selenium安装
pip install selenium
代码库安装地址稍后给出,也可自行百度
先上完整代码
有需要请在下方留言,由于水平有限,部分代码并不严谨
from selenium import webdriver
import time
import sys,os
from PIL import Image,ImageDraw
import re
import time
from PIL import ImageGrab
from pytesser import *
reload(sys)
sys.setdefaultencoding('utf-8')
#getPixel为去噪算法
def getPixel(image,x,y,G,N):
L = image.getpixel((x,y))
if L > G:
L = True
else:
L = False
nearDots = 0
if L == (image.getpixel((x - 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y + 1)) > G):
nearDots += 1
if nearDots < N:
return image.getpixel((x,y-1))
else:
return None
# 降噪
# 根据一个点A的RGB值,与周围的8个点的RBG值比较,设定一个值N(0