使用htmlparser能不能直接得到两个标签之间的内容,应该怎么做?
还有就是用htmlparser能不能直接得到链接的文本,就是<a>和</a>之间的内容,应该怎么做?

解决方案 »

  1.   

    利用htmlparser提取HTML中的文本信息- -
                                           package bot;import org.htmlparser.Node;
    import org.htmlparser.NodeFilter;
    import org.htmlparser.Parser;
    import org.htmlparser.util.NodeList;/**
     * 用于处理HTML信息的工具集合
     * @author liudong
     */
    public class HtmlUtils { /**
      * 抽取纯文本信息
      * @param inputHtml
      * @return
      */
     public static String extractText(String inputHtml) throws Exception{
      StringBuffer text = new StringBuffer();
      
      Parser parser = Parser.createParser(new String(inputHtml.getBytes(),"8859_1"));
      //遍历所有的节点
      NodeList nodes = parser.extractAllNodesThatMatch(new NodeFilter(){
       public boolean accept(Node node) {
        return true;
       }});
      Node node = nodes.elementAt(0);
      text.append(new String(node.toPlainTextString().getBytes("8859_1")));
      return text.toString();
     }
     
     public static void main(String[] args) throws Exception{
      String text = extractText("点击这里回到首页");
      System.out.println(text);
     }
     
    }
      

  2.   

    dxadnwfn(可米第二) ,老大你能不能不粘网上的文章