如何将Jsoup文档保存到HTML文件? [英] How to save a Jsoup Document to an HTML file?

查看:1181
本文介绍了如何将Jsoup文档保存到HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此方法将网页检索到 org.jsoup.nodes.Document 对象:

I have used this method to retrieve a webpage into an org.jsoup.nodes.Document object:

myDoc = Jsoup.connect(myURL).ignoreContentType(true).get();

我该怎么办?将此对象写入HTML文件?
方法 myDoc.html() myDoc.text() myDoc.toString()不输出文档的所有元素。

How should I write this object to a HTML file? The methods myDoc.html(), myDoc.text() and myDoc.toString() don't output all elements of the document.

javascript元素中的某些信息在解析时可能会丢失。例如,Instagram媒体页面源中的timestamp。

Some information in a javascript element can be lost in parsing it. For example, "timestamp" in the source of an Instagram media page.

推荐答案

有些元素被忽略的事实,必须是由于Jsoup正规化的尝试。

The fact that there are elements that are ignored, must be due to the attempt of normalization by Jsoup.

为了获得服务器的确切输出而没有任何形式的规范化,请使用此功能。

In order to get the server's exact output without any form of normalization use this.

Connection.Response html = Jsoup.connect("PUT_URL_HERE").execute();
System.out.println(html.body());

这篇关于如何将Jsoup文档保存到HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆