如何将Jsoup(Java html解析器)中生成的文档转换为字符串 [英] How do I convert a document made in Jsoup (the Java html parser) into a string
问题描述
我有一个jsoup中的文档,看起来像这样
文档doc = Jsoup.connect(http: //en.wikipedia.org /)得到()。
如何将 doc
转换为你知道吗?
文档doc = Jsoup.connect(http://en.wikipedia.org/)。get();
String htmlString = doc.toString();
当文档扩展元素时,它还具有得到了方法 html(),根据 API 检索元素的内部HTML。这应该工作:
文档doc = Jsoup.connect(http://en.wikipedia.org/)。得到();
String htmlString = doc.html();
其他信息:
每个 Document 对象都有一个对内部类 Document.OutputSettings 的实例的引用,可以通过方法 outputSettings() of Document。在那里,您可以使用setter prettyPrint(true / false)启用/禁用漂亮打印。有关进一步信息,请参阅文档和 Document.OutputSettings 的API
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.
Have you tried:
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
String htmlString = doc.toString();
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:
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
String htmlString = doc.html();
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
这篇关于如何将Jsoup(Java html解析器)中生成的文档转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!