seleniumとApiumの簡単な検証コード自動認識方法

1545 ワード

tesseract-ocrとPILの2つのツールを使います。
システムはWindows 64ビットですので、PILを再インストールする際にはちょっと問題があります。手順は以下の通りです。
1、ダウンロード tesseract-ocr-setup-3.2.02 exeをインストールし(次のステップをダブルクリックしてからfinish)、そしてtesseract-ocrのインストールディレクトリをシステム環境変数に追加します。
2、PIPの取り付け
ダウンロード:http://download.csdn.net/detail/chenlei_525/9377602
そして運転してください。ソースコードです。
python Xxx.py
3、Pillowをダウンロードする
http://download.csdn.net/detail/chenlei_525/9377606
pipでpip install XX.whlをインストールします。
4、すべての準備が整いましたら、書類を通します。
from PIL import Image導入PIL
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はappumもseleniumもできます。