您的位置:首页 > 移动开发

selenium和Appium的简单验证码自动识别方法

2016-07-04 15:57 387 查看
用到tesseract-ocr和PIL两个工具。系统为Windows 64位,因此再安装PIL的时候有点小问题,步骤如下:1、下载 tesseract-ocr-setup-3.02.02.exe安装(双击一路下一步然后finish),然后把tesseract-ocr的的安装目录添加到系统环境变量中2、安装PIP下载:http://download.csdn.net/detail/chenlei_525/9377602然后运行一下就可以了(是Python)源代码python Xxxx.py
3、下载Pillowhttp://download.csdn.net/detail/chenlei_525/9377606

通过pip安装 pip install XXX.whl4、一切准备就绪后在文件中通过from PIL import Image引入PIL

[python] view plain copy
def identifyingCode(self,driver,startx,starty,endx,endy):

u'''''获取验证码

(startx,xstarty)---------------------------------

| 要截取的图片范围 |

| |

---------------------------------- (endx,endy)

'''

driver.get_screenshot_as_file(os.getcwd()+'\\cirsschan.jpg')

imGetScreen = Image.open(os.getcwd()+'\\cirsschan.jpg')

box=(startx,starty,endx,endy)

imIndentigy = imGetScreen.crop(box)

imIndentigy.save(os.getcwd()+'\\indent.jpg')

strCommand = 'tesseract.exe '+os.getcwd()+'\\indent.jpg ' +os.getcwd()+'\\indet.txt'

print strCommand

os.system(strCommand)

rfindet = open(os.getcwd()+'\\indet.txt.txt','r')

strIndet= rfindet.readline()

return strIndet

上述过程自己验证可以使用,driver既可以appium也可以selenium,都可以
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息