@Test public void testExtractHTMLheaders() { logger.info("extractHTMLheaders"); String text = " <h1>a1</h1> <h1 class='s'>a2</h1> <h2>b1</h2>"; Map<String, List<String>> expResult = new HashMap<>(); for(int i=1;i<=6;++i) { expResult.put("H"+i, new ArrayList<>()); } expResult.get("H1").add("a1"); expResult.get("H1").add("a2"); expResult.get("H2").add("b1"); Map<String, List<String>> result = HTMLParser.extractHTMLheaders(text); assertEquals(expResult, result); }
public static Map<String, List<String>> extractHTMLheaders(String html) { Map<String, List<String>> hxtagsMap = new HashMap<>(); for(int i=1;i<=6;++i) { hxtagsMap.put("H"+i, new ArrayList<>()); } Matcher m = HX_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String tagType = m.group(1).toUpperCase(Locale.ENGLISH); String content = m.group(2); hxtagsMap.get(tagType).add(clear(content)); } } return hxtagsMap; }
HTMLParser { public static Map<String, List<String>> extractHTMLheaders(String html) { Map<String, List<String>> hxtagsMap = new HashMap<>(); for(int i=1;i<=6;++i) { hxtagsMap.put("H"+i, new ArrayList<>()); } Matcher m = HX_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String tagType = m.group(1).toUpperCase(Locale.ENGLISH); String content = m.group(2); hxtagsMap.get(tagType).add(clear(content)); } } return hxtagsMap; } }
HTMLParser { public static Map<String, List<String>> extractHTMLheaders(String html) { Map<String, List<String>> hxtagsMap = new HashMap<>(); for(int i=1;i<=6;++i) { hxtagsMap.put("H"+i, new ArrayList<>()); } Matcher m = HX_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String tagType = m.group(1).toUpperCase(Locale.ENGLISH); String content = m.group(2); hxtagsMap.get(tagType).add(clear(content)); } } return hxtagsMap; }  }
HTMLParser { public static Map<String, List<String>> extractHTMLheaders(String html) { Map<String, List<String>> hxtagsMap = new HashMap<>(); for(int i=1;i<=6;++i) { hxtagsMap.put("H"+i, new ArrayList<>()); } Matcher m = HX_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String tagType = m.group(1).toUpperCase(Locale.ENGLISH); String content = m.group(2); hxtagsMap.get(tagType).add(clear(content)); } } return hxtagsMap; }  static String replaceImgWithAlt(String html); static String removeComments(String html); static String unsafeRemoveAllTags(String html); static String safeRemoveAllTags(String html); static String removeNonTextTagsAndAttributes(String html); static String extractText(String html); static String extractTitle(String html); static Map<HyperlinkPart, List<String>> extractHyperlinks(String html); static Map<String, String> extractMetatags(String html); static Map<String, List<String>> extractHTMLheaders(String html); }
HTMLParser { public static Map<String, List<String>> extractHTMLheaders(String html) { Map<String, List<String>> hxtagsMap = new HashMap<>(); for(int i=1;i<=6;++i) { hxtagsMap.put("H"+i, new ArrayList<>()); } Matcher m = HX_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String tagType = m.group(1).toUpperCase(Locale.ENGLISH); String content = m.group(2); hxtagsMap.get(tagType).add(clear(content)); } } return hxtagsMap; }  static String replaceImgWithAlt(String html); static String removeComments(String html); static String unsafeRemoveAllTags(String html); static String safeRemoveAllTags(String html); static String removeNonTextTagsAndAttributes(String html); static String extractText(String html); static String extractTitle(String html); static Map<HyperlinkPart, List<String>> extractHyperlinks(String html); static Map<String, String> extractMetatags(String html); static Map<String, List<String>> extractHTMLheaders(String html);  }