为了账号安全,请及时绑定邮箱和手机立即绑定

jsoup如何禁止格式化文档元素?

jsoup如何禁止格式化文档元素?

德玛西亚99 2019-03-28 19:11:34
使用jsoup分析html,需要获取某个元素的html代码,并且要求代码不要格式化(缩进和换行)。使用jsoup获取到此元素之后,tostring方法返回的结果直接对代码进行了格式化。请问如何禁止jsoup对代码进行格式化?
查看完整描述

1 回答

?
12345678_0001

TA贡献1802条经验 获得超5个赞

Document.outputSettings().prettyPrint(false);


/**

* Get if pretty printing is enabled. Default is true. If disabled, the HTML output methods will not re-format

* the output, and the output will generally look like the input.

* @return if pretty printing is enabled.

*/

public boolean prettyPrint() {

    return prettyPrint;

}


/**

 * Enable or disable pretty printing.

 * @param pretty new pretty print setting

 * @return this, for chaining

 */

public OutputSettings prettyPrint(boolean pretty) {

    prettyPrint = pretty;

    return this;

}


查看完整回答
反对 回复 2019-04-25
  • 1 回答
  • 0 关注
  • 649 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号