Java lucene 技术(8): 解析html页面
可能Html页面是目前数量最多的数据存储格式,因此,lucene内置了html解析器,用以提供对html页面的解析,解析器对内部细节进行了较好的封装,我们所需做的,只是根据它提供的API,进行相应的程序编写。
程序8.1提供了一个解析html页面的方式。
BufferedReader br =
new BufferedReader(
new FileReader("E:/t.html"));
HTMLParser hp = new HTMLParser(br);
String title = hp.getTitle();
String content = hp.getSummary();
Properties meta
t.html页面源文件如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>北京龙卷风科技</title>
</head>
<body>
<p>
龙卷风科技_优秀的信息检索平台
网址:http://www.tornado.cn
</p>
</body>
</html>
解析结果为:
title………北京龙卷风科技
content………龙卷风科技_优秀的信息检索平台网址:http://www.tornado.cn
meta properties………..{content-type=text/html; charset=utf-8}
另外,lucene提供了几种HTMLParser构造方法,如:
HTMLParser
(
HTMLParserTokenManager
tm)
HTMLParser
(
InputStream
stream)
HTMLParser
(Readerstream)
让我们从自身的禁锢中放心地飞出去,重新审视自己,