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