import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlLabel;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.util.Cookie;
public class htmlunitTestRefer
{
/**
* @param args
* @throws IOException
* @throws MalformedURLException
* @throws FailingHttpStatusCodeException
*/
/*
* public static void main(String[] args) { URL url=null; try { url = new
* URL(
* "http://p.yiqifa.com/c?s=55109db0&w=596861&c=17162&i=38061&l=0&e=zldmm&t=http://www.yintai.com"
* ); } catch (MalformedURLException e1) { // TODO Auto-generated catch
* block e1.printStackTrace(); } // String referrer =
* "http://www.google.com/"; WebClient webClient=new WebClient();
*
* System.out.println(webClient.getBrowserVersion().isFirefox()); WebRequest
* request=new WebRequest(url); request.setCharset("UTF-8");
* System.out.println(request.getCharset()); //
* request.setAdditionalHeader("Referer", referrer); HtmlPage page=null; try
* { page = webClient.getPage(request); URL url1=page.getUrl();
* webClient.getRefreshHandler().handleRefresh(page, url1, 0); //
* System.out.println(page.getWebResponse().getContentAsString()); //
* System.out.println(page.getWebResponse().getResponseHeaders()); String
* backHtml=page.getWebResponse().getContentAsString(); Document
* backDocument = Jsoup.parse(backHtml);
* System.out.println(backDocument.toString());
*
* Set<Cookie> cookie= webClient.getCookieManager().getCookies();
* System.out.println(cookie); //
* System.out.println(page.getBody().asText()); //
* System.out.println(page.get); } catch (FailingHttpStatusCodeException e)
* { // TODO Auto-generated catch block e.printStackTrace(); } catch
* (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
* } // String docReferrer =
* (String)page.executeJavaScript("document.referrer"
* ).getJavaScriptResult(); // System.out.println(docReferrer); }
*/
// Get the first page
/*public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException
{
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient
.getPage("http://172.16.17.185:8083/backLogin.do");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlTextInput button = form.getInputByName("userName");
final HtmlPasswordInput textField = form.getInputByName("password");
final HtmlButtonInput login = (HtmlButtonInput) form.getByXPath(".//*[@id='loginbtn']").get(0);
// Change the value of the text field
textField.setValueAttribute("admin");
button.setValueAttribute("admin");
// Now submit the form by clicking the button and get back the second
// page.
final HtmlPage page2 = login.click();
System.out.println(page2.getWebResponse().getContentAsString());
}*/
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException
{
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient
.getPage("http://www.126.com/");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getForms().get(0);
final HtmlLabel button =(HtmlLabel) form.getByXPath("//*[@id='idPlaceholder']").get(0);
final HtmlLabel textField = (HtmlLabel) form.getByXPath("//*[@id='pwdPlaceholder']").get(0);
final HtmlButton login = (HtmlButton) form.getByXPath("//*[@id='loginBtn']").get(0);
// Change the value of the text field
textField.type("");
button.type("");
// Now submit the form by clicking the button and get back the second
// page.
final HtmlPage page2 = login.click();
System.out.println(page2.getWebResponse().getContentAsString());
}
}
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlLabel;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.util.Cookie;
public class htmlunitTestRefer
{
/**
* @param args
* @throws IOException
* @throws MalformedURLException
* @throws FailingHttpStatusCodeException
*/
/*
* public static void main(String[] args) { URL url=null; try { url = new
* URL(
* "http://p.yiqifa.com/c?s=55109db0&w=596861&c=17162&i=38061&l=0&e=zldmm&t=http://www.yintai.com"
* ); } catch (MalformedURLException e1) { // TODO Auto-generated catch
* block e1.printStackTrace(); } // String referrer =
* "http://www.google.com/"; WebClient webClient=new WebClient();
*
* System.out.println(webClient.getBrowserVersion().isFirefox()); WebRequest
* request=new WebRequest(url); request.setCharset("UTF-8");
* System.out.println(request.getCharset()); //
* request.setAdditionalHeader("Referer", referrer); HtmlPage page=null; try
* { page = webClient.getPage(request); URL url1=page.getUrl();
* webClient.getRefreshHandler().handleRefresh(page, url1, 0); //
* System.out.println(page.getWebResponse().getContentAsString()); //
* System.out.println(page.getWebResponse().getResponseHeaders()); String
* backHtml=page.getWebResponse().getContentAsString(); Document
* backDocument = Jsoup.parse(backHtml);
* System.out.println(backDocument.toString());
*
* Set<Cookie> cookie= webClient.getCookieManager().getCookies();
* System.out.println(cookie); //
* System.out.println(page.getBody().asText()); //
* System.out.println(page.get); } catch (FailingHttpStatusCodeException e)
* { // TODO Auto-generated catch block e.printStackTrace(); } catch
* (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
* } // String docReferrer =
* (String)page.executeJavaScript("document.referrer"
* ).getJavaScriptResult(); // System.out.println(docReferrer); }
*/
// Get the first page
/*public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException
{
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient
.getPage("http://172.16.17.185:8083/backLogin.do");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlTextInput button = form.getInputByName("userName");
final HtmlPasswordInput textField = form.getInputByName("password");
final HtmlButtonInput login = (HtmlButtonInput) form.getByXPath(".//*[@id='loginbtn']").get(0);
// Change the value of the text field
textField.setValueAttribute("admin");
button.setValueAttribute("admin");
// Now submit the form by clicking the button and get back the second
// page.
final HtmlPage page2 = login.click();
System.out.println(page2.getWebResponse().getContentAsString());
}*/
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException
{
final WebClient webClient = new WebClient();
final HtmlPage page1 = webClient
.getPage("http://www.126.com/");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getForms().get(0);
final HtmlLabel button =(HtmlLabel) form.getByXPath("//*[@id='idPlaceholder']").get(0);
final HtmlLabel textField = (HtmlLabel) form.getByXPath("//*[@id='pwdPlaceholder']").get(0);
final HtmlButton login = (HtmlButton) form.getByXPath("//*[@id='loginBtn']").get(0);
// Change the value of the text field
textField.type("");
button.type("");
// Now submit the form by clicking the button and get back the second
// page.
final HtmlPage page2 = login.click();
System.out.println(page2.getWebResponse().getContentAsString());
}
}