WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6); client.setTimeout(60000); client.setRedirectEnabled(true); client.setJavaScriptEnabled(true); client.setThrowExceptionOnFailingStatusCode(false); client.setThrowExceptionOnScriptError(false); client.setCssEnabled(false); client.setUseInsecureSSL(true);
webClient.getCache().clear(); webClient.setJavaScriptEnabled(true); webClient.setThrowExceptionOnScriptError(false); webClient.setRedirectEnabled(false); webClient.setAjaxController(new SyncAllAjaxController());
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6); client.setTimeout(60000); client.setRedirectEnabled(true); client.setJavaScriptEnabled(true); client.setThrowExceptionOnFailingStatusCode(false); client.setThrowExceptionOnScriptError(false); client.setCssEnabled(false); client.setUseInsecureSSL(true); HtmlPage page = null; try { page = client.getPage("http://www.whatever.com"); } catch (Exception e) { // TODO Auto-generated catch block } if (page.getWebResponse().getStatusCode() == 404) { System.out.println("Page not found"); } // Post a request WebRequest request = new WebRequest(new URL("http://www.whatever.com/post_url")); request.setHttpMethod(HttpMethod.POST); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair("login", userLogin)); params.add(new NameValuePair("pass", userPassword)); request.setRequestParameters(params); page = client.getPage(request);
//set browser WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10); //not to throw exception on javascript error webClient.setThrowExceptionOnScriptError(false); //set page to access final HtmlPage homepageEn = webClient.getPage("http://protein.rnet.missouri.edu:8080/MongoTest/"); //get the form by id HtmlForm form = homepageEn.getFirstByXPath("//form[@id='input_form']"); //setup the fields to use HtmlTextInput mailField = form.getInputByName("mail"); HtmlPasswordInput passwordField = form.getInputByName("password"); //define the submit button (defined by value) HtmlSubmitInput submitButton = form.getInputByValue("submit"); //change the value of text fields mailField.setValueAttribute("somemail@xyzmail.com"); passwordField.setValueAttribute("some_password"); //finally submit the form by clicking the button final HtmlPage resultsPage = submitButton.click();
public String getPageSourceFromBrowser(String url) throws SiteAnalizeException { WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6); HtmlPage firstPage = null; String result = null; try { webClient.setJavaScriptEnabled(true); webClient.setThrowExceptionOnScriptError(false); webClient.setCssEnabled(false); webClient.setUseInsecureSSL(false); webClient.setRedirectEnabled(true); firstPage = webClient.getPage(new URL(url)); result = firstPage.getWebResponse().getContentAsString("UTF-8"); DomNodeList<HtmlElement> button = firstPage.getElementsByTagName("a"); for (HtmlElement htmlElement : button) { if(htmlElement.asText().equals("Buy Now")) { HtmlPage page = htmlElement.click(); //HtmlElement button2 = page.getElementById("market_buynow_dialog_addfunds"); //HtmlPage page2 = button2.click(); String htmlBody = page.getWebResponse().getContentAsString(); System.out.println(htmlBody); } } }
webClient.setThrowExceptionOnScriptError(false); webClient.setJavaScriptEnabled(true);
webClient.setThrowExceptionOnScriptError(false); webClient.setJavaScriptEnabled(true); webClient.setAjaxController(new NicelyResynchronizingAjaxController());