Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在从URL读取的文本中保留换行符_Java_Jsoup - Fatal编程技术网

Java 无法在从URL读取的文本中保留换行符

Java 无法在从URL读取的文本中保留换行符,java,jsoup,Java,Jsoup,我正在使用Jsoup从URL读取文本。以下链接提供了一些将正文转换为文本时保留新行的提示 我使用以下行来转换标记 String prettyPrintedBodyFragment = Jsoup.clean(body, "", Whitelist .none().addTags("br", "p", "h1"), new OutputSettings() .prettyPrint(true)); System.out.println(p

我正在使用Jsoup从URL读取文本。以下链接提供了一些将正文转换为文本时保留新行的提示

我使用以下行来转换标记

  String prettyPrintedBodyFragment = Jsoup.clean(body, "", Whitelist
            .none().addTags("br", "p",  "h1"), new OutputSettings()
            .prettyPrint(true));
  System.out.println(prettyPrintedBodyFragment);
我仍然在单行中获取正文/内容。有什么线索吗

编辑:这是完整的源代码,我只在一行中看到输出

 public static void main(String[] args) throws Exception {

        Connection conn = Jsoup.connect("http://finance.yahoo.com/");
        Document doc  = conn.get();

         String body = doc.body().text();

        String prettyPrintedBodyFragment = Jsoup.clean(body, "", Whitelist
                .none().addTags("br", "p",  "h1"), new OutputSettings()
                .prettyPrint(true));

        System.out.println(prettyPrintedBodyFragment);



    }
更改:

String body=doc.body().text()

致:

String body=doc.body().html()


由于您已经在转储标记,您的
白名单
在格式化文本时无法包含这些标记。

这对我很有用。你想解析什么url?用源代码编辑了原始帖子,以便从finance.yahoo.com阅读