截取html中的某个节点
String content = "<meta property=\"og:description\" content=\"freeCodeCamp Earth 有 127,712 位成員。 Welcome to freeCodeCamp Earth!\n" + "\n" + "This is a relaxing place to discuss coding and share your accomplishments.\n" + "\n" + "To keep this Facebook group civil, our moderator team...\" />\n" + "\t<meta property=\"og:url\" content=\"https://www.facebook.com/groups/321090721625587/\" />\n" + "\t<meta property=\"og:locale\" content=\"en_US\" />"; String readText = ""; // Pattern p = Pattern.compile("<div\\s*class=[\"']mail-trace[\"'](.*)>(.*)<\\/div>"); Pattern p = Pattern.compile("<meta\\s*property=[\"']og:url[\"'](.*)(.*)\\/>"); Matcher matcher = p.matcher(content); if (matcher.find()) { for (int i = 0; i <= matcher.groupCount() && StringUtils.isEmpty(readText); i++) { readText += matcher.group(i); } } System.out.println(readText);
<meta property="og:description" content="freeCodeCamp Earth 有 127,712 位成員。 Welcome to freeCodeCamp Earth! This is a relaxing place to discuss coding and share your accomplishments. To keep this Facebook group civil, our moderator team..." /> <meta property="og:url" content="https://www.facebook.com/groups/321090721625587/" /> 要匹配内容! <meta property="og:locale" content="en_US" />