Exemplo n.º 1
0
        /// <summary>
        /// 获取html代码中的description
        /// </summary>
        /// <param name="html">html内容</param>
        /// <param name="ignoreCas">是否忽略大小写</param>
        /// <returns>description</returns>
        public static string GetDescription(string html, bool ignoreCas)
        {
            string description = HttpCollects.GetMetaString(html, "<meta([\\s]*)name=\"description\"([\\s]*)content=\"", "\"([\\s]*)/?>", ignoreCas);

            if (string.IsNullOrEmpty(description))
            {
                description = HttpCollects.GetMetaString(html, "<meta([\\s]*)content=\"", "\"([\\s]*)name=\"description\"([\\s]*)/?>", ignoreCas);
            }
            return(description);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取html内容中的Title
        /// </summary>
        /// <param name="html">html内容</param>
        /// <param name="ignoreCas">是否忽略大小写</param>
        /// <returns>标签title</returns>
        public static string GetTitle(string html, bool ignoreCas)
        {
            string title = HttpCollects.GetMetaString(html, "<meta name=\"title\"([\\s]*)content=\"", "\"([\\s]*)/?>", ignoreCas);

            if (string.IsNullOrEmpty(title))
            {
                string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)";
                System.Text.RegularExpressions.Regex ex = new System.Text.RegularExpressions.Regex(regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                return(ex.Match(html).Value.Trim());
            }
            return(title);
        }