HtmlUnit to view source

Jake Sankey picture Jake Sankey · May 13, 2011 · Viewed 11.4k times · Source

HtmlUnit for Java is great but I haven't been able to figure out how to view the full source or return the source of a web site as a string. can anyone help me with this?

I know the follow will read the site but now I just want to return the source to a string.

HtmlPage mySite = webClient.getPage("http://mysite.com");

Thanks!

Answer

Jeremy picture Jeremy · May 13, 2011

From looking through the API, my thought would be:

mySite.getWebResponse().getContentAsString();