WebClient client = new WebClient(); client.getOptions().setThrowExceptionOnScriptError(false);
WebClient client = new WebClient(); try { client.getOptions().setUseInsecureSSL(true); client.getOptions().setThrowExceptionOnFailingStatusCode(false); client.getOptions().setThrowExceptionOnScriptError(false); WebRequest requestSettings = new WebRequest(new URL(REST_URL), methodCall);
final WebClient webClient = new WebClient(); webClient.getOptions().setJavascriptEnable(false);
WebClient webClient = new WebClient(BrowserVersion.CHROME); String url = "https://github.com/login"; webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = webClient.getPage(url); DomElement form = (DomElement) page.querySelector("form"); System.out.println(form.asXml()); webClient.close();
WebClient client = new WebClient(); client.getOptions().setUseInsecureSSL(true);
public static void main(String[] args) throws IOException { FileUtils.cleanDirectory(new File("c://temp/htmlunit/aa")); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setTimeout(5000); System.out.println("******************loaded**********************************"); try { HtmlPage page = webClient.getPage("https://www.google.com"); webClient.waitForBackgroundJavaScriptStartingBefore(1000); webClient.waitForBackgroundJavaScript(1000); page.save(new File("c://temp/htmlunit/aa/index.html")); } catch (Exception e) { System.out.println("******************catch***********************************"); e.printStackTrace(); } webClient.close(); System.out.println("******************finished********************************"); }
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF); final WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setTimeout(10000); try { HtmlPage page = webClient.getPage("http://www.bloomberg.com/search?query=Apple"); System.out.println(page.getTitleText()); ScriptResult result = page.executeJavaScript("document.querySelector(\"#content > div > section > section.search-results__content > section.content-stories > div.search-result-items > div:nth-child(1) > article > div > h1 > a\").click()"); page = (HtmlPage)result.getNewPage(); System.out.println(page.getTitleText()); } catch (Exception e) { e.printStackTrace(); } finally { webClient.close(); }
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF); final WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setTimeout(10000); try { HtmlPage htmlPage = webClient.getPage("http://qatarsale.com/EnMain.aspx"); Document doc = Jsoup.parse(htmlPage.asXml()); System.out.println(doc.select("[id$=Label10]").text()); ScriptResult result = htmlPage.executeJavaScript("__doPostBack('GridView1','Page$2')"); htmlPage = (HtmlPage)result.getNewPage(); Thread.sleep(3000); // delay needed for lazy loading, there might be something cleaner doc = Jsoup.parse(((HtmlPage)htmlPage).asXml()); System.out.println(doc.select("[id$=Label10]").text()); } catch (Exception e) { e.printStackTrace(); } finally { webClient.close(); }
try(final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setUseInsecureSSL(true); webClient.waitForBackgroundJavaScript(5 * 1000); HtmlPage page = webClient.getPage("https://jumpseller.cl/support/webpayplus/"); String stringToSave = page.asXml(); // It's a string with full HTML-code, if need you can save it to file. webClient.close(); }
WebClient client = new WebClient(BrowserVersion.CHROME); client.getOptions().setJavaScriptEnabled(true); client.getOptions().setThrowExceptionOnScriptError(false); client.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = client.getPage("http://yoursite.com/"); HtmlTextInput user = page.getElementByName("USER_ID"); user.setValueAttribute("youruser"); HtmlPasswordInput password = page.getElementByName("PWD"); password.setValueAttribute("yourpassword"); HtmlButtonInput loginButton = (HtmlButtonInput) page.getByXPath("//input[@class='loginbtn']").get(0); page = loginButton.click(); System.out.println(page.asText()); client.close();
WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = webClient.getPage("https://scholar.google.com/"); HtmlInput searchBox = (HtmlInput) page.getElementById("gs_hp_tsi"); searchBox.setValueAttribute("internet of things for smart cities"); HtmlButton googleSearchSubmitButton = page.getElementByName("btnG"); page = googleSearchSubmitButton.click(); HtmlAnchor anchor = page.getAnchorByText("Cite"); anchor.click(); webClient.waitForBackgroundJavaScript(5000); HtmlAnchor linkBibTex = page.getAnchorByText("BibTeX"); TextPage neededPage = linkBibTex.click(); System.out.println(neededPage.getContent()); webClient.close();
webclient.getOptions().setJavaScriptEnabled(true); HtmlPage page = webclient.getPage(url1);
try { String url = "https://www.linkedin.com/uas/login?goback=&trk=hb_signin"; final WebClient webClient = new WebClient(); webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); final HtmlPage loginPage = webClient.getPage(url); //Get Form By name final HtmlForm loginForm = loginPage.getFormByName("login"); final HtmlSubmitInput button = loginForm.getInputByName("signin"); final HtmlTextInput usernameTextField = loginForm.getInputByName("session_key"); final HtmlPasswordInput passwordTextField = loginForm.getInputByName("session_password"); usernameTextField.setValueAttribute(userName);//your Linkedin Username passwordTextField.setValueAttribute(password);//Your Linkedin Password final HtmlPage responsePage = button.click(); String htmlBody = responsePage.getWebResponse().getContentAsString(); System.out.println(htmlBody); } catch (Exception ex) { ex.printStackTrace(); }