python 识别平台验证码

By 肖奈
2017-10-17
4572 read
#coding=utf-8
from
 PIL import Image
import pytesseract
from
 selenium import webdriver

url=
'http://192.168.0.178:8080/WebGis/'
driver = webdriver.Chrome(
'chromedriver.exe'
)
driver.maximize_window() 
#将浏览器最大化,以获取更清晰的校验码图片
driver.
get
(url)
driver.save_screenshot(
'f://gps.png'
) 
#截取当前网页,该网页有我们需要的验证码
imgelement = driver.find_element_by_id(
'verifyCodeImg'
) 
#通过id定位验证码
location = imgelement.location 
#获取验证码的x,y轴
size = imgelement.size  
#获取验证码的长宽
rangle=(
int
(location[
'x'
]),         
int
(location[
'y'
]),         
int
(location[
'x'
]+size[
'width'
]),         
int
(location[
'y'
]+size[
'height'
])) 
#写成我们需要截取的位置坐标
i=Image.open(
'f:gps.png'
) 
#打开截图
verifycodeimage=i.crop(rangle)   
#使用Image的crop函数,从截图中再次截取我们需要的区域
verifycodeimage.save(
'f://verifycodeimage.png'
)
image=Image.open(
'f:verifycodeimage.png'
)
#print image
vcode=pytesseract.image_to_string(image).strip() 
#使用image_to_string识别验证码
print vcode


按钮弹窗事件
django url 正则

Comments

暂无评论,还不快来坐沙发...

Leave a Reply