Package org.htmlparser.visitors

Examples of org.htmlparser.visitors.TagFindingVisitor


        createParser(html);
    }

    public void testTagFound() throws Exception
    {
        TagFindingVisitor visitor =
            new TagFindingVisitor(new String[] { "HEAD" });
        parser.visitAllNodesWith(visitor);
        assertEquals("HEAD found", 1, visitor.getTagCount(0));
    }
View Full Code Here


        assertEquals("HEAD found", 1, visitor.getTagCount(0));
    }

    public void testTagsFound() throws Exception
    {
        TagFindingVisitor visitor =
            new TagFindingVisitor(new String[] { "LI" });
        parser.visitAllNodesWith(visitor);
        assertEquals("LI tags found", 2, visitor.getTagCount(0));
    }
View Full Code Here

        assertEquals("LI tags found", 2, visitor.getTagCount(0));
    }

    public void testMultipleTags() throws Exception
    {
        TagFindingVisitor visitor =
            new TagFindingVisitor(new String[] { "LI", "BODY", "UL", "A" });
        parser.visitAllNodesWith(visitor);
        assertEquals("LI tags found", 2, visitor.getTagCount(0));
        assertEquals("BODY tag found", 1, visitor.getTagCount(1));
        assertEquals("UL tag found", 1, visitor.getTagCount(2));
        assertEquals("A tag found", 1, visitor.getTagCount(3));
    }
View Full Code Here

        assertEquals("A tag found", 1, visitor.getTagCount(3));
    }

    public void testEndTags() throws Exception
    {
        TagFindingVisitor visitor =
            new TagFindingVisitor(
                new String[] { "LI", "BODY", "UL", "A" },
                true);
        parser.visitAllNodesWith(visitor);
        assertEquals("LI tags found", 2, visitor.getTagCount(0));
        assertEquals("BODY tag found", 1, visitor.getTagCount(1));
        assertEquals("UL tag found", 1, visitor.getTagCount(2));
        assertEquals("A tag found", 1, visitor.getTagCount(3));
        assertEquals("BODY end tag found", 1, visitor.getEndTagCount(1));
    }
View Full Code Here

    private void identify(String string) throws Exception
    {
        String[] tagsBeingChecked = { "TABLE", "DIV", "SPAN" };

        Parser parser = new Parser("http://www.amazon.com");
        TagFindingVisitor tagFinder =
            new TagFindingVisitor(tagsBeingChecked, true);
        parser.visitAllNodesWith(tagFinder);
        for (int i = 0; i < tagsBeingChecked.length; i++)
        {
            System.out.println(
                "Number of "
                    + tagsBeingChecked[i]
                    + " begin tags = "
                    + tagFinder.getTagCount(i));
            System.out.println(
                "Number of "
                    + tagsBeingChecked[i]
                    + " end tags = "
                    + tagFinder.getEndTagCount(i));
        }

    }
View Full Code Here

    Node[] tags;
    {
      String htmlContents = IOUtils2.readString(htmlFile);
      Lexer lexer = new Lexer(new Page(htmlContents));
      Parser parser = new Parser(lexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET));
      TagFindingVisitor visitor = new TagFindingVisitor(new String[]{tagName});
      parser.visitAllNodesWith(visitor);
      tags = visitor.getTags(0);
    }
    // convert into List<TagNode>
    List<TagNode> tagNodes = Lists.newArrayList();
    CollectionUtils.addAll(tagNodes, tags);
    return tagNodes;
View Full Code Here

        String [] tagsBeingChecked =
        {"TABLE","DIV","SPAN"};

        Parser parser =
            new Parser(url);
        TagFindingVisitor tagFinder =
            new TagFindingVisitor(tagsBeingChecked, true);
        parser.visitAllNodesWith(tagFinder);
        for (int i=0;i<tagsBeingChecked.length;i++) {
            System.out.println(
                "Number of "+tagsBeingChecked[i]+" begin tags = "+
            tagFinder.getTagCount(i));
            System.out.println(
                "Number of "+tagsBeingChecked[i]+" end tags = "+
                tagFinder.getEndTagCount(i));
        }

    }
View Full Code Here

  public void setUp() {
    createParser(html);
  }

  public void testTagFound() throws Exception {
    TagFindingVisitor visitor = new TagFindingVisitor(new String[] { "HEAD" });
    parser.visitAllNodesWith(visitor);
    assertEquals("HEAD found", 1, visitor.getTagCount(0));
  }
View Full Code Here

    parser.visitAllNodesWith(visitor);
    assertEquals("HEAD found", 1, visitor.getTagCount(0));
  }

  public void testTagsFound() throws Exception {
    TagFindingVisitor visitor = new TagFindingVisitor(new String[] { "LI" });
    parser.visitAllNodesWith(visitor);
    assertEquals("LI tags found", 2, visitor.getTagCount(0));
  }
View Full Code Here

    parser.visitAllNodesWith(visitor);
    assertEquals("LI tags found", 2, visitor.getTagCount(0));
  }

  public void testMultipleTags() throws Exception {
    TagFindingVisitor visitor = new TagFindingVisitor(new String[] { "LI", "BODY", "UL", "A" });
    parser.visitAllNodesWith(visitor);
    assertEquals("LI tags found", 2, visitor.getTagCount(0));
    assertEquals("BODY tag found", 1, visitor.getTagCount(1));
    assertEquals("UL tag found", 1, visitor.getTagCount(2));
    assertEquals("A tag found", 1, visitor.getTagCount(3));
  }
View Full Code Here

TOP

Related Classes of org.htmlparser.visitors.TagFindingVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.