title: How to get dynamic contents of any web page in DOM tree using JSOUP in Java
body: <p>In my project, which parses the HTML page, then uses the DOM tree for different operations, just like, comparing templates of two URLS.</p>
  
  <p>For that, I am using <strong>JSOUP</strong>.</p>
  
  <p>But it does not able to load Dynamic contents in DOM tree.</p>
  
  <p>Can you tell me how can I load dynamic content using JSOUP in Java, or can you tell me any other method for doing the same?</p>
  
  <p><strong>EDIT NO. 1</strong></p>
  
  <p>As <a href="https://stackoverflow.com/questions/12625043/getting-jsoup-to-support-dynamically-generated-html-by-javascript">given link</a> shows, it works using <strong>PhantomJS</strong> and <strong>Zombie.js</strong> in Java. Can you tell me how can I do this ?</p>
  
  <p><strong>Edit No. 2</strong></p>
  
  <p>I first try to get dynamic page by using Selenium, and the code is as follows,</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
  
   // Selenium
   WebDriver driver = new FirefoxDriver();
   driver.get("ANY URL HERE");  
   String html_content = driver.getPageSource();
   driver.get("ANOTHER URL HERE");
   String html_content1 = driver.getPageSource();
   driver.close();
  
   // Jsoup makes DOM here by parsing HTML content
   Document doc1 = Jsoup.parse(html_content);
   Document doc2 = Jsoup.parse(html_content1);
  
   // OPERATIONS USING DOM TREE
  }
  </code></pre>
  
  <p>But this takes lots of time after optimizing also. Now as per your instructions, I moved to HtmlUnit. 
  But I am not able to make code, that gets Dynamic Page source code into String , and then I use this String for further paring using Jsoup, help me to write that code using HtmlUnit.</p>
  
  <p><em>Code using HtmlUnit</em> :- </p>
  
  <pre><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;
  
  /**
   *
   * @author jhamb
   */
  public class HtmlUnit {
  
      @Test
      public void homePage() throws Exception {
          final WebClient webClient = new WebClient();
          final HtmlPage page = webClient.getPage("http://www.jabong.com/Yepme-3-4Th-Sleeve-Printed-Blue-Top-Mksp-191481.html");
  
          Document ht = page.getOwnerDocument();
          System.out.println(ht);
  
          webClient.closeAllWindows();
      }
  
      public static void main(String[] args) throws Exception {
          HtmlUnit htmlUnit = new  HtmlUnit();
          htmlUnit.homePage();
      }
  }
  </code></pre>