如何使用 HtmlUnit 获取 HTML 页面

发布于 2025-01-06 18:20:28 字数 132 浏览 2 评论 0原文

我知道你可能认为这个问题很愚蠢,但我需要使用 HtmlUnit。但是,它以 XML 或文本形式返回页面。

我不知道如何获得纯HTML(与浏览器返回的源代码相同)

我需要这个,因为我需要使用一些编写的模块。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛刀软妹 2025-01-13 18:20:28

您可以使用以下代码来实现您的目标:

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

请参阅 WebResponse.html#getContentAsString() 方法的 javadocs

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文