final HtmlPage page2 = button.click(); webClient.waitForBackgroundJavaScript(10000) String originalHtml = page2.asXml(); return originalHtml;
//Get Page HtmlPage page1 = webClient.getPage("https://login-url/"); //Wait for background Javascript webClient.waitForBackgroundJavaScript(10000); //Get full page _after_ javascript has rendered it fully System.out.println(page1.asXml());
List<WebWindow> windows = webClient.getWebWindows(); for(WebWindow w : windows){ HtmlPage hpage = (HtmlPage) w.getEnclosedPage(); System.out.println(hpage.asXml()); }
List<WebWindow> windows = webClient.getWebWindows(); for(WebWindow w : windows){ HtmlPage hpage2 = (HtmlPage) w.getEnclosedPage(); System.out.println("-------------------------------------"); System.out.println(hpage2.asXml()); }
String myUrl = "https://www.wearvr.com/#game_id=game_4"; try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) { HtmlPage myPage = ((HtmlPage) webClient.getPage(myUrl)); System.out.println(myPage.asXml()); } catch (FailingHttpStatusCodeException | IOException e) { e.printStackTrace(); }
HtmlPage page2= (HtmlPage) webClient.getPage("https://controlcenter-itv2.centurylink.com/business/controlcenter/ordering/initiate-orders-whsl/batch"); System.out.println(page2.asXml()); HtmlForm form1 =(HtmlForm) page2.getElementById("batchOrderForm");
public class SavePage { public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException { WebClient client = new WebClient(); HtmlPage page = client.getPage("https://www.google.co.in"); FileWriter writer = new FileWriter("d:\\google.html"); writer.write(page.asXml()); //Save page on file system writer.close(); } }
HtmlPage page = null; try { page = webClient.getPage(url); } catch (Exception e) { System.out.println("Get page error"); } JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager(); while (manager.getJobCount() > 0) { Thread.sleep(1000); } System.out.println(page.asXml()); return page;
String strURL = "https://www.checkmytrip.com" ; java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF); java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_31)) { webClient.setAjaxController(new NicelyResynchronizingAjaxController()); HtmlPage myPage = ((HtmlPage) webClient.getPage(strURL)); webClient.waitForBackgroundJavaScript(10 * 1000); String theContent = myPage.asXml(); System.out.println(theContent); }
public class Htmlunitscraper { private static String s = "website"; public static HtmlPage scrapeWebsite() throws IOException { final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage(s); return page.asXml(); } }
try { HtmlPage page = webClient.getPage("http://www.w3schools.com/HTML/tryit.asp?filename=tryhtml_noframes"); HtmlInlineFrame frame = page.getFirstByXPath("//iframe[@name='view']"); page = webClient.getPage(page.getFullyQualifiedUrl(frame.getSrcAttribute())); System.out.println(page.asXml()); } catch (Exception e) { e.printStackTrace(); }
public void print(HtmlPage page) { System.out.println("\n\n\n RAW REQUEST BODY \n" + getRawRequestBody()); System.out.println("\n\n\n RAW RESPONSE \n" + getRawResponse()); System.out.println("Response Headers: " + page.getWebResponse().getResponseHeaders()); System.out.println("\n\n\n ********************************* \n" + page.asXml()); System.out.println("\n\n\n **************************** \n" + webClient.getCookieManager().getCookies()); System.out.println("\n\n\n *********************************"); }
WebClient webClient = new WebClient(); WebRequest wr = new WebRequest(new URL("http://url.to.post"), HttpMethod.POST); List<NameValuePair> parameters = Arrays.asList( new NameValuePair("name", "john"), new NameValuePair("age", "28")); wr.setRequestParameters(parameters); HtmlPage page = webClient.getPage(wr); System.out.println(page.asXml());
// load page using HTML Unit and fire scripts WebClient webClient = new WebClient(); HtmlPage myPage = webClient.getPage(myURL); // convert page to generated HTML and convert to document doc = Jsoup.parse(myPage.asXml()); // do something with html content System.out.println(doc.html()); // clean up resources webClient.close();
@Test public void homePage() throws Exception { final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); final String pageAsXml = page.asXml(); assertTrue(pageAsXml.contains("<body class=\"composite\">")); final String pageAsText = page.asText(); assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols")); }
// capture rendered page WebClient webClient = new WebClient(); HtmlPage myPage = webClient.getPage("https://pokevision.com"); // convert to jsoup dom Document doc = Jsoup.parse(myPage.asXml()); // extract data using jsoup selectors Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]"); for (Element image : images) { System.out.println("src : " + image.attr("src")); } // clean up resources webClient.close();
// load page using HTML Unit and fire scripts WebClient webClient = new WebClient(); HtmlPage myPage = webClient.getPage(myURL); // convert page to generated HTML and convert to document Document doc = Jsoup.parse(myPage.asXml(), baseURI); // clean up resources 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(); }
/** * Get the content page as a text String. * * @return the text */ public String getPageAsText() { if (getContentPage() instanceof HtmlPage) return ((HtmlPage)getContentPage()).asXml(); if (getContentPage() instanceof TextPage) return ((TextPage)getContentPage()).getContent(); if (getContentPage() instanceof XmlPage) return ((XmlPage)getContentPage()).asXml(); if (getContentPage() instanceof JavaScriptPage) return ((JavaScriptPage)getContentPage()).getContent(); throw new IllegalStateException("This page can not be converted to text. Page type is " + getContentPage().getClass().getName()); }
@Test public void testELWithParameters(@ArquillianResource URL baseURL) throws Exception { WebClient client = new WebClient(); HtmlPage page = client.getPage(new URL(baseURL, "charlie.jsf")); page.asXml(); HtmlSpan oldel = getFirstMatchingElement(page, HtmlSpan.class, "oldel"); assertNotNull(oldel); final String charlie = "Charlie"; assertEquals(charlie, oldel.asText()); HtmlSpan newel = getFirstMatchingElement(page, HtmlSpan.class, "newel"); assertNotNull(newel); assertEquals(charlie, newel.asText()); }