How to get a HTML page using HtmlUnit

感情迁移 提交于 2019-11-30 18:14:37

问题


I know you may think this question is stupid, but I need to use HtmlUnit. However, it returns a page either as XML or as text.

I don't how to get the pure HTML (the same as the source code that browsers return)

I need this, because I need to use some written modules. Any ideas?


回答1:


You can use the following piece of code to achieve your goal:

WebClient webClient = new WebClient();
Page page = webClient.getPage("http://example.com");
WebResponse response = page.getWebResponse();
String content = response.getContentAsString();

See javadocs of the WebResponse.html#getContentAsString() method.



来源:https://stackoverflow.com/questions/9354099/how-to-get-a-html-page-using-htmlunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!