OCR (Optical Character Recognition) is mounted

First, install homebrew

1) Open the terminal input commands directly mounted:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2) the installation is complete, verify that the installation was successful, enter the query version command:

        brew --version

Even encountered problems related to installation Note:

After installation, use the brew find command, but always suggested: -bash: brew: command not found

By investigation found / usr / local / bin not in the PATH, where required profiling operation

        1, the input terminal: sudo vim .bash_profile (modified state enters a carriage return)

        2, add: PATH = "; $ PATH:. / Usr / local / bin"

        3, esc Exit command,: wq Save the file and exit vi

        4, source .bash_profile to make configuration changes to take effect

You can use the brew command again.

https: //docs.brew.sh--- use help, refer to the official documentation!


 

Second, the installation Imagemagick and Tesseract library

brew install imagemagick

brew install tesseract

Installation screenshots:

 

 

 


Third, install Selenium and ChromeDriver

    1, an input terminal:

      (win)pip install selenium

       (linux) pip3 install selenium

        pip3 list selenium   

 

 

  2, download the corresponding ChromeDriver

         Download: HTTP : / / npm .taobao .org / Mirrors / chromedriver /

  3. Verify that the installation was successful

 

chromedriver
Starting ChromeDriver 2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db) on port 9515
Only local connections are allowed.

 4. Test Code

from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.baidu.com')
operation result:

 

5. Through OCR recognition CAPTCHA (Example)

  import pytesseract as pytesseract
    from selenium import webdriver
    import time
    from PIL import Image

    browser = webdriver.Chrome()

    browser.get('https://xxxxxxx')
    time.sleep(6)
    browser.find_element_by_id("userName").send_keys("xxxxxxx")
    browser.find_element_by_id("pwd").send_keys("xxxxxx")
    time.sleep(6)
    codeElement = browser.find_element_by_id ( "pin") # 1, input box acquired codes
    imgElement = browser.find_element_by_class_name ( "login-pin-img") # 2, image acquisition codes
    browser.save_screenshot('/Users/pangyongjuan/Documents/test/01.png')#3、 截取全屏
    yanzhenga = browser.find_element_by_class_name("login-pin-img")
    left = yanzhenga.location['x']#4、 通过location定位x,y
    top = yanzhenga.location['y']
    elementWidth = yanzhenga.location['x'] + yanzhenga.size['width']#5、 通过x,y的值拼接长和宽
    elementHeight = yanzhenga.location['y'] + yanzhenga.size['height']
    picture = Image.open('/Users/pangyongjuan/Documents/test/01.png')#6、 打开刚截取的全屏图
    picture = picture.crop((left, top, elementWidth, elementHeight))#7、# 定位到需要截取的地方
    picture.save('/Users/pangyongjuan/Documents/test/02.png')#8、 截取成功并保存到本地

  

Guess you like

Origin www.cnblogs.com/-pyj/p/12072305.html