开源组件:
https://sourceforge.net/projects/htmlunit/
demo
public void post() { try { WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_7); client.setJavaScriptEnabled(false); HttpWebConnection httpwebconnection = new HttpWebConnection(client); // httpwebconnection.setUseInsecureSSL(true); ProxyConfig proxyConfig = new ProxyConfig(); proxyConfig.setProxyHost("代理"); proxyConfig.setProxyPort(8080); client.setProxyConfig(proxyConfig); client.setWebConnection(httpwebconnection); HtmlPage page = client.getPage("http://www.cmd5.com/default.aspx"); HtmlElement textElemnt = page .getElementById("ctl00_ContentPlaceHolder1_TextBoxInput"); HtmlElement selectElement = page .getElementById("ctl00_ContentPlaceHolder1_InputHashType"); HtmlElement btnElement = page .getElementById("ctl00_ContentPlaceHolder1_Button1"); textElemnt.click(); textElemnt.type("e10adc3949ba59abbe56e057f20f883e"); selectElement.click(); selectElement.type("MD5"); // 点击事件,获取一个新的页面 HtmlPage resultPage = (HtmlPage) btnElement.click(); // 返回页面数据 String result = resultPage.asText(); // 截取字符串 result = result.substring(result.indexOf("查询结果:") + 5).trim(); int index = result.indexOf("[添加备注]"); result = result.substring(0, index).trim(); System.out.println(result); } catch (Exception ex) { } }
自动化执行效果图