Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlUnit - Convert an HtmlPage into HTML string?

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!

like image 966
Peter Avatar asked Jun 27 '11 18:06

Peter


2 Answers

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

like image 167
Rodney Gitzel Avatar answered Sep 30 '22 15:09

Rodney Gitzel


I'm not 100% certain I understood the question correctly, but maybe this will address your issue:

page.getWebResponse().getContentAsString()

like image 26
Sergey O. Avatar answered Sep 30 '22 17:09

Sergey O.