如何使用HtmlUnit获取HTML页面 [英] How to get a HTML page using HtmlUnit
本文介绍了如何使用HtmlUnit获取HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道你可能认为这个问题很愚蠢,但我需要使用HtmlUnit。但是,它以XML或文本形式返回页面。
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.
我不知道如何获取纯HTML(与浏览器返回的源代码相同)
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?
推荐答案
您可以使用以下代码来实现目标:
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();
参见所述WebResponse.html#getContentAsString的javadocs中()方法。
这篇关于如何使用HtmlUnit获取HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文