<input id="news_Id" name="newsId" type="hidden" value="8434"/>
怎样用htmlparser把 8434 提取出来?

解决方案 »

  1.   

    public class Testhtmlparser {
    public static void main(String[] args) {
           Parser parser = null;
          NodeFilter filter = null;
           NodeList list = null;         
           try {
               parser = new Parser("http://www.cando100.com/news/20090226/12356117756402369890.html");
               //创建过超链接滤器          
               filter = new HasAttributeFilter( "id","news_Id" );           
               //过滤节点内容, 返回节点集
               list = parser.extractAllNodesThatMatch(filter);
               //遍历           
                if(list!=null) {
                           for (int i = 0; i < list.size(); i++) {                 
             InputTag inputtag = (InputTag) list.elementAt(i);   
                            System.out.println(inputtag.getAttribut ("value"));                                     
                    }        
                      }       
            } catch (Exception e) {            e.printStackTrace();        }     }
    }