htmlunit 校正驗證碼

來源:互聯網
上載者:User

標籤:pat   contain   password   .sh   pwd   image   ring   des   val   

htmlUnit 校正驗證碼 

直接上代碼

 1       String url = "http://www.zycg.gov.cn/"; 2          3         WebclientUtil webClientUtils = new WebclientUtil(); 4         WebClient webClient = webClientUtils.getWebClient(); 5          6         HtmlPage page = webClient.getPage(url); 7                      8         HtmlElement username = page.getFirstByXPath("//*[@id=‘u_name‘]"); 9         HtmlElement password = page.getFirstByXPath("//*[@id=‘u_pwd1‘]");10         HtmlElement valiCode = page.getFirstByXPath("//*[@id=‘yzm‘]");11         HtmlImage valiCodeImg = (HtmlImage) page.getFirstByXPath("//*[@id=‘img_random‘]");12         ImageReader imageReader = valiCodeImg.getImageReader();13         BufferedImage bufferedImage = imageReader.read(0);14 15         JFrame f2 = new JFrame();16         JLabel l = new JLabel();17         l.setIcon(new ImageIcon(bufferedImage));18         f2.getContentPane().add(l);19         f2.setSize(100, 100);20         f2.setTitle("驗證碼");21         f2.setVisible(true);22         23         String valicodeStr = JOptionPane.showInputDialog("請輸入驗證碼:");24         f2.setVisible(false);25         HtmlForm submit = page.getFirstByXPath("//*[@id=‘submitForm‘]");26         27         username.click();28         username.type("zhongkeruan");29         password.click();30         password.type("62570007");31         valiCode.click();32         valiCode.type(valicodeStr);33         34         35         ScriptResult result = page.executeJavaScript("dl()");36         page = (HtmlPage) result.getNewPage();37         38         if(page.asText().contains("下一頁")){39             System.out.println("登入成功");40         }else{41             System.out.println("登入失敗");42         }43         System.out.println(page.asText());

 

htmlunit 校正驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.