如何将 Jsoup(Java html 解析器)中生成的文档转换为字符串
我有一个用 jsoup 制作的文档,如下所示
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
How do i conversion that doc
into a string。
I have a document that was made in jsoup that looks like this
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
How do i convert that doc
into a string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过:
由于 Document 扩展了 Element,它还具有方法 html(),该方法根据 “检索元素的内部 HTML” a href="http://jsoup.org/apidocs/">API。所以这应该有效:
附加信息:
每个Document对象都有一个对内部类Document.OutputSettings实例的引用,可以访问它通过 Document 的方法outputSettings()。在那里,您可以使用 setter prettyPrint(true/false) 启用/禁用漂亮打印。请参阅 Document 和 Document.OutputSettings 的 API 了解更多信息
Have you tried:
As Document extends Element it also has got the method html() which "Retrieves the element's inner HTML" according to the API. So that should work:
Additional Info:
Each Document object has got a reference to an instance of the inner class Document.OutputSettings which can be accessed via the method outputSettings() of Document. There you can enable/disable pretty-printing by using the setter prettyPrint(true/false). See the API for Document and Document.OutputSettings for furtherinformation
doc.toString()
可以工作,doc.outerHtml()
也可以。doc.toString()
works, as doesdoc.outerHtml()
.将字符串解析为文档后,您可以使用它的文档函数
After parsing the string to document then you can use on it document functions