selenium -驗證碼處理


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便是驗證碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM