【问题标题】:Jericho plain text how to separate textJericho纯文本如何分隔文本
【发布时间】:2012-12-22 04:09:07
【问题描述】:

我正在尝试使用 Jericho 使用以下代码解析纯文本:

    public static String getPlainText(String html) {
    Source htmlSource = new Source(html);
    Segment htmlSeg = new Segment(htmlSource, 0, html.length());
    Renderer htmlRend = new Renderer(htmlSeg);
   // System.out.println(htmlRend.toString());
    return htmlRend.toString();
}

但是对于以下 html 片段:

    Phone (808) 845-0000<br />
    Fax (808) 842-3616
    <a href="mailto:helpdesk@progressive-hi.com">
    helpdesk@progressive-hi.com</a>         

我得到了输出:

电话 (808) 845-0000 传真 (808) 842-3616helpdesk@progressive-hi.com

现在我想要的是标签中的所有文本都应该彼此分开,即传真和电子邮件应该彼此分开。有没有办法做到这一点?

谢谢

【问题讨论】:

    标签: java html


    【解决方案1】:

    问题解决了。

    Source source=new Source(new URL(sourceUrlString));
    System.out.println(source.getTextExtractor().setIncludeAttributes(true).toString());
    

    http://jericho.htmlparser.net/samples/console/src/ExtractText.java

    【讨论】:

    • 告诉我们您是如何解决的,并将您的答案标记为“正确答案”。
    • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post
    • 请不要添加“谢谢”作为答案。相反,请为您认为有帮助的答案投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 2023-03-15
    • 1970-01-01
    • 2020-04-23
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多