mop(猫扑)登陆

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;


public class TestUnit {
	public static void testHomePage() throws Exception {  
        // 新建一个WebClient对象,此对象相当于浏览器   
        final WebClient webClient=new WebClient(BrowserVersion.INTERNET_EXPLORER_7);  
       
        webClient.setJavaScriptEnabled(false);
        webClient.setJavaScriptTimeout(300);
        webClient.setAppletEnabled(false);
        webClient.setPopupBlockerEnabled(false);
        webClient.setThrowExceptionOnFailingStatusCode(false);
        webClient.setThrowExceptionOnScriptError(false);
        webClient.setCssEnabled(false);
        webClient.setActiveXNative(false);
        webClient.setRedirectEnabled(true);
        webClient.setActiveXNative(false);
        // 首页登录地址
         URL url=new URL("http://hi.mop.com/SysHome.do");
        HtmlPage page=webClient.getPage(url);  
        //System.out.println("sss"+page.getTitleText()+":"+page.asText());  
        HtmlTextInput InputUserName = (HtmlTextInput)page.getElementByName("nickname"); 

        //HtmlPage page = webClient.getPage("http://hi.mop.com/SysHome.do"); 

       //HtmlTextInput InputUserName = (HtmlTextInput)page.getElementByName("nickname"); 

        HtmlPasswordInput InputPassword = (HtmlPasswordInput)page.getElementByName("password"); 

        InputUserName.setText("用户名"); 

        InputPassword.setText("密码"); 

        HtmlButton hb = (HtmlButton)page.getElementById("login"); 

        page = hb.click();
       System.out.println(page.getTitleText()+":"+page.asText());      
    } 
	public static void main(String[] args) {
		try {
			//URL url=new URL("http://hi.mop.com/SysHome.do");
			testHomePage();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

 

 

 

就是模拟一个浏览器

你可能感兴趣的:(mop(猫扑)登陆)