Http://htsoft.org/html/y2011/822_using-htmlunit-landing-site-with-captcha-image.html
Use Htmlunit to log in a website with captcha imagesSeptember 15, 2011 ⁄ programming language ⁄ a total of 1266 characters ⁄ font size small big ⁄ no comments ⁄ read 7,088 times
Take Baidu Statistics as an example, explain how to use Htmlunit login with verification code of the website
Baidu Statistics Login Code try{webclient client = new WebClient (browserversion.internet_explorer_7); Client.setjavascriptenabled ( FALSE); Httpwebconnection httpwebconnection = new httpwebconnection (client); Httpwebconnection.setuseinsecuressl (true); Client.setwebconnection (httpwebconnection); HtmlPage page = client.getpage ("http://tongji.baidu.com"); HtmlElement username = Page.getelementbyid ("username"); HtmlElement password = Page.getelementbyid ("password"); HtmlElement Valicode = Page.getelementbyid ("Valicode"); HtmlImage valicodeimg = (htmlimage) Page.getelementbyid ("Cas_code"); ImageReader ImageReader = Valicodeimg.getimagereader (); BufferedImage bufferedimage = imagereader.read (0); JFrame F2 = new JFrame (); JLabel L = new JLabel (); L.seticon (new ImageIcon (BufferedImage)); F2.getcontentpane (). Add (L); f2.setsize (100, 100); F2.settitle ("Verification Code"); F2.setvisible (true); String valicodestr = Joptionpane.showinputdialog ("Please enter a code:"); f2.setvisible (false); HtmlElement submit = Page.getelementbyid ("submit"); Htmlsubmitinput Submit2 = (htmlsubmitinput) submit;username.click (); Username.type ("Gabazi");p Assword.click ();p assword.type ("******"); Valicode.click (); Valicode.type (VALICODESTR); HtmlPage resultpage = Submit2.click (); System.out.println (Resultpage.astext ()); System.exit (0);} catch (Exception e) {e.printstacktrace ();}
Use Htmlunit to log in to a website with a CAPTCHA image