java - jsoup如何禁止格式化代码?
黄舟
黄舟 2017-04-18 10:17:22
0
1
762

使用jsoup分析html,需要获取某个元素的html代码,并且要求代码不要格式化(缩进和换行)。使用jsoup获取到此元素之后,tostring方法返回的结果直接对代码进行了格式化。

请问如何禁止jsoup对代码进行格式化?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

모든 응답(1)
Ty80

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;
}
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!