Given a html
file that has <script> tags which update the DOM on the fly, is it possible to run this file through some java code to get the dynamic DOM
generated by java script.
I.e If I were to launch the file in a browser, browser would load the script tag and run java script and update DOM accordingly and render it. I want this final DOM but without a browser support.
My application is Java app running in Tomcat which fetches the html content from a DB. I need to expand this html content to get the "dynamic" content after applying the java script. Is this feasible through Java APIs?
EDIT
I tried HtmlUnit to load the content and parse the page content. However MathJax expanded content is not available when I fetch xml content from HtmlPage
.
URL url = new URL("http://www.example.com");
StringWebResponse response = new StringWebResponse(getPageHTMLContentFromDB(), url);
WebClient client = new WebClient();
HtmlPage page = HTMLParser.parseHtml(response, client.getCurrentWindow());
System.out.println(page.asXml()); // this line does not print the MathJax expanded DOM.
When I launch the html content obtained from DB in a browser, I see the correct DOM (updated by MathJax).