Selenium processing of CAPTCHA
Selenium-CAPTCHA processing
1.WEB website adds the function of CAPTCHA in order to prevent clients from maliciously.
The common method for 2.selenium to deal with CAPTCHA is through cooike. For general websites, CAPTCHA is not difficult to identify. You can use the third-party platform CAPTCHA interface. Take Qunar as an example, CAPTCHA is a picture, and we just need to save the picture.
Call a third-party platform.
Http://wiki.ruokuai.com/ downloads the java interface document and calls the following API directly
Public static String createByPost (String username, String password, String typeid, String timeout, String softid, String softkey, String filePath) {String result = ""; String param = String.format ("username=%s&password=%s&typeid=%s&timeout=%s&softid=%s&softkey=%s", username, password, typeid, timeout, softid, softkey) Try {File f = new File (filePath); if (null! = f) {int size = (int) f.length (); byte [] data = new byte [size]; FileInputStream fis = new FileInputStream (f); fis.read (data, 0, size); if (null! = fis) fis.close () If (data.length > 0) result = RuoKuai.httpPostImage ("http://api.ruokuai.com/create.txt", param, data);}} catch (Exception e) {result =" unknown problem ";} return result;}
Example:
First take a screenshot of the CAPTCHA and save it to the project path
Getting ER7C is the verification code.