2012-12-22 16 views
0

我試圖解析使用傑里科用下面的代碼的純文本:傑里科純文本如何分隔文本

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:[email protected]"> 
    [email protected]</a>   

我收到輸出:

電話(808)845-0000傳真:(808)[email protected]

現在我想要的是標籤內的所有文本應該彼此分開,即傳真和電子郵件應該彼此分開。有什麼辦法可以做到這一點?

謝謝

回答

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

+1

告訴我們你是如何解決它,並標記你回答爲「正確答案」。 – Marwelln

+0

這不提供問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲望](http://stackoverflow.com/faq#reputation),你將能夠[評論任何帖子](http://stackoverflow.com/privileges/comment)。 –

+0

請不要添加「謝謝」作爲答案。相反,投票答案,你覺得有幫助。 – tune2fs