KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > BadTagIdentifier


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/BadTagIdentifier.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:55 $
10
// $Revision: 1.17 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests;
28
29 import org.htmlparser.Parser;
30 import org.htmlparser.visitors.TagFindingVisitor;
31
32 public class BadTagIdentifier {
33
34     public BadTagIdentifier() {
35         super();
36     }
37
38     public static void main(String JavaDoc[] args)
39         throws Exception JavaDoc {
40         BadTagIdentifier badTags =
41             new BadTagIdentifier();
42         badTags.identify("http://www.amazon.com");
43     }
44
45     private void identify(String JavaDoc url)
46         throws Exception JavaDoc{
47         String JavaDoc [] tagsBeingChecked =
48         {"TABLE","DIV","SPAN"};
49
50         Parser parser =
51             new Parser(url);
52         TagFindingVisitor tagFinder =
53             new TagFindingVisitor(tagsBeingChecked, true);
54         parser.visitAllNodesWith(tagFinder);
55         for (int i=0;i<tagsBeingChecked.length;i++) {
56             System.out.println(
57                 "Number of "+tagsBeingChecked[i]+" begin tags = "+
58             tagFinder.getTagCount(i));
59             System.out.println(
60                 "Number of "+tagsBeingChecked[i]+" end tags = "+
61                 tagFinder.getEndTagCount(i));
62         }
63
64     }
65 }
66
Popular Tags