-2

I had tried Htmlunit but that doesn't work so can u help me with API or any other solution which I can study and get the solution.Thanku

import com.gargoylesoftware.htmlunit.BrowserVersion;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class GetPageSourceAfterJS {
    public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {

        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF); /* comment out to turn off annoying htmlunit warnings */
        WebClient webClient;
        webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setJavaScriptEnabled(true);
        //System.out.println("Loading page now: "+url);
        HtmlPage page = webClient.getPage("http://www.thehindu.com/");
        webClient.waitForBackgroundJavaScript(30 * 1000); /* will wait JavaScript to execute up to 30s */

        String pageContent = page.asText();
        System.out.println("pageContent");

        //get divs which have a 'class' attribute of 'bucket'
       // List<?> buckets = page.getByXPath("//div[@class='bucket']");
       // System.out.println("Found "+buckets.size()+" 'bucket' divs.");

        //System.out.println("#FULL source after JavaScript execution:\n "+pageAsXml);
    }
} can u tell me why this failing to run
  • what are you asking? what has this got to do with java? what have you tried so far? – Scary Wombat Jul 13 '17 at 05:03
  • save HTML output of page after execution of the page's javascript I want to know this I had seen selenium web driver but it's come in testing part so I'm not clear about it and I had used Htmlunit – Niti kapoor Jul 13 '17 at 05:15

1 Answers1

-3

If the DOM generated element has an ID, you can get it by

<someVariable> = document.getElementById(id);

And then getting the <someVariable>.outerHTML.

Antti29
  • 2,953
  • 12
  • 34
  • 36