I try to get a dynamic page from URL. I am working in Java. I have done this using Selenium, but it takes lots of time. As it takes time to invoke driver of Selenium. That's why I shifted to HtmlUnit, as it is GUILess Browser. But my HtmlUnit implementation shows some exception.
Question :-
- How can I correct my HtmlUnit implementation.
- Is the page produced by Selenium is simiar to the page produced by HtmlUnit? [ Both are dynamic or not? ]
My selenium code is :-
public static void main(String[] args) throws IOException {
// Selenium
WebDriver driver = new FirefoxDriver();
driver.get("ANY URL HERE");
String html_content = driver.getPageSource();
driver.close();
// Jsoup makes DOM here by parsing HTML content
Document doc = Jsoup.parse(html_content);
// OPERATIONS USING DOM TREE
}
HtmlUnit code:-
package XXX.YYY.ZZZ.Template_Matching;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Assert;
import org.junit.Test;
public class HtmlUnit {
public static void main(String[] args) throws Exception {
//HtmlUnit htmlUnit = new HtmlUnit();
//htmlUnit.homePage();
WebClient webClient = new WebClient();
HtmlPage currentPage = webClient.getPage("http://www.jabong.com/women/clothing/womens-tops/?source=women-leftnav");
String textSource = currentPage.asText();
System.out.println(textSource);
}
}
It shows exception :-
