1.WEB網站爲了防止客戶機惡意攻擊,加入驗證碼功能java
2.selenium處理驗證碼時經常使用的方法是經過cooike,對於通常網站驗證碼識別難度不大,可使用第三方平臺驗證碼接口,以去哪兒網爲例,驗證碼爲圖片,咱們只要把圖片保存下來api
調用第三方平臺。網站
http://wiki.ruokuai.com/ 下載java接口文檔,直接調用如下接口spa
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 = "未知問題"; } return result; }
例:code
先對驗證碼進行截圖,保存到項目路徑下orm
獲取ER7C即是驗證碼blog