htmlunit 模拟登陆 https

欢迎大家访问我的个人网站 萌萌的IT人,后续所有的文章都会在此发布

--------------------------------------------------------------------------------------------WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_7);
HttpWebConnection httpwebconnection = new HttpWebConnection(client);
		httpwebconnection.setUseInsecureSSL(true);
		client.setWebConnection(httpwebconnection);
	    //获取某网站页面
	    HtmlPage page = client.getPage("https://xxx.xxxx.com");
	    //获取某页面元素,可通过id或name,(具体方式很多 --Foxswily)
	    HtmlElement username = page.getElementById("username");
	    HtmlElement password = page.getElementById("password");
	    HtmlElement submit = page.getElementById("username");
	    //HtmlElement elmt = page.getElementByName("somename");
	//    HtmlForm form;
	    //此例以文本框为例,先点击,再输入,完全跟真浏览器行为一致
	    username.click();
	    username.type("xxx8");
	    password.click();
	    password.type("xxxx2");
	    DomNodeList<HtmlElement> nodelist =page.getElementsByTagName("input");
		//获取按钮
	    HtmlSubmitInput loginBtn = (HtmlSubmitInput)nodelist.get(8);
	    //点击并获得返回结果
 System.out.println(loginBtn .getWebResponse().getContentAsString());
	    Page resultPage = loginBtn.click();
	//    HtmlPage mail = client.getPage(resultPage.getWebResponse().getWebRequest()); 
	 

 

你可能感兴趣的:(浏览器)