Use Htmlunit to log in a website with captcha images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.