首页 > Web开发 > 详细

jericho解析html

时间:2017-07-08 13:15:19      阅读:315      评论:0      收藏:0      [点我收藏+]

1.导入jar包

技术分享


2.实现源代码

package com.zhishang.lucene;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

/**
 * Created by Administrator on 2017/7/8.
 */
public class HtmlBeanUtil {

    @Test
    public void parseHtml(){
        String path = "G:\\data\\index.html";

        try {
            Source sc = new Source(new File(path));
            Element element = sc.getFirstElement(HTMLElementName.TITLE);
            System.out.println(element.getTextExtractor().toString());
            System.out.println(sc.getTextExtractor().toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1945451

jericho解析html

原文:http://suyanzhu.blog.51cto.com/8050189/1945451

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!