将 HTML 源代码从变量读取到 HTMLUNIT
我看到的所有 htmlunit 示例都使用 getPage 通过 URL 从网站检索 HTML。
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
我在字符串变量中保存了一个 HTML 片段,但找不到从变量中为其提供 HTML 的方法。
我尝试将 String 转换为 HtmlPage 但这不起作用。
HtmlPage page = (HtmlPage) htmlFragment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以将 HTML 片段(可能包含在标准 html/head/body 标记中)写入临时文件,并将其 URL 用于您的 Web 客户端。例如(未经测试):
或者,您可以构建您的拥有一个带有虚假 URL 和临时 HtmlPage “nofollow">
WebResponse
和WebWindow
但这可能需要大量的黑客工作。Perhaps you could write the HTML fragment (possibly wrapped in the standard html/head/body tags) into a temp file and use its URL for your web client. For example (untested):
Alternatively, you might be able to construct your own
HtmlPage
with a phony URL and ad-hocWebResponse
andWebWindow
but that might require a lot of hacking.