htmlparser 自定义标签

//构造自定义标签类

static class bTag extends CompositeTag {
     private static final String[] mIds = new String[] {"B"};
     public String[] getIds (){
         return (mIds);
     }
 }

 

//注册自定义标签

PrototypicalNodeFactory factory = new PrototypicalNodeFactory();
   factory.registerTag(new bTag());
   parser.setNodeFactory(factory);

//获取自定义标签

NodeFilter filter = new TagNameFilter("B");
    NodeList list = parser.extractAllNodesThatMatch(filter);
    for(int i=0;i<list.size();i++){
     System.out.println(list.elementAt(i).toPlainTextString());
    }

 

 

 

你可能感兴趣的:(HtmlParser)