HtmlUnit - Convert an HtmlPage into HTML string?

Peter picture Peter · Jun 27, 2011 · Viewed 11.5k times · Source

I'm using HtmlUnit to generate the HTML for various pages, but right now, the best I can do to get the page into the raw HTML that the server returns is to convert the HtmlPage into an XML string.

This is somewhat annoying because the XML output is rendered by web browsers differently than the raw HTML would. Is there a way to convert an HtmlPage into raw HTML instead of XML?

Thanks!

Answer

Rodney Gitzel picture Rodney Gitzel · Jun 30, 2011

page.asXml() will return the HTML. page.asText() returns it rendered down to just text.