use*_*995 5 html-parsing apache-tika boilerpipe
我只是想知道如何使用Tika从html中提取主文本和纯文本?
也许一种可能的解决方案是使用BoilerPipeContentHandler,但你有一些示例/演示代码来显示它吗?
首先十分感谢
这是一个示例:
public String[] tika_autoParser() {
String[] result = new String[3];
try {
InputStream input = new FileInputStream(new File("/Users/nazanin/Books/Web crawler.pdf"));
ContentHandler textHandler = new BodyContentHandler();
Metadata metadata = new Metadata();
AutoDetectParser parser = new AutoDetectParser();
ParseContext context = new ParseContext();
parser.parse(input, textHandler, metadata, context);
result[0] = "Title: " + metadata.get(metadata.TITLE);
result[1] = "Body: " + textHandler.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (TikaException e) {
e.printStackTrace();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)