@Test public void testExtractMetatags() { logger.info("extractMetatags"); String text = "<html><head> <meta name = \"description\" content = \"Some description.\" />\n" + " < meta name = 'keywords' content = 'Some keywords.' >"; Map<String, String> expResult = new HashMap<>(); expResult.put("description", "Some description."); expResult.put("keywords", "Some keywords."); Map<String, String> result = HTMLParser.extractMetatags(text); assertEquals(expResult, result); }
public static Map<String, String> extractMetatags(String html) { Map<String, String> metatagsMap = new HashMap<>(); Matcher m = METATAG_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String name = m.group(1); String content = m.group(2); metatagsMap.put(clear(name), clear(content)); } } return metatagsMap; }
HTMLParser { public static Map<String, String> extractMetatags(String html) { Map<String, String> metatagsMap = new HashMap<>(); Matcher m = METATAG_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String name = m.group(1); String content = m.group(2); metatagsMap.put(clear(name), clear(content)); } } return metatagsMap; } }
HTMLParser { public static Map<String, String> extractMetatags(String html) { Map<String, String> metatagsMap = new HashMap<>(); Matcher m = METATAG_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String name = m.group(1); String content = m.group(2); metatagsMap.put(clear(name), clear(content)); } } return metatagsMap; }  }
HTMLParser { public static Map<String, String> extractMetatags(String html) { Map<String, String> metatagsMap = new HashMap<>(); Matcher m = METATAG_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String name = m.group(1); String content = m.group(2); metatagsMap.put(clear(name), clear(content)); } } return metatagsMap; }  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, String> extractMetatags(String html) { Map<String, String> metatagsMap = new HashMap<>(); Matcher m = METATAG_PATTERN.matcher(html); while (m.find()) { if(m.groupCount()==2) { String name = m.group(1); String content = m.group(2); metatagsMap.put(clear(name), clear(content)); } } return metatagsMap; }  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);  }