Esempio n. 1
0
        /// <summary>
        /// Get the meta value from debug page or page source
        /// provide a 'constentStartWith' string to filter the selection if there are more than one same meta tag.
        /// </summary>
        /// <param name="metaName">The metadata name to get the value</param>
        /// <param name="sourceType">choose the source from pageSource or debugSource</param>
        /// <param name="contentStartWith">the string to filter the meta tag/param>
        /// <returns></returns>
        public string GetMetaValue(string metaName, SourceTypes sourceTypes = SourceTypes.debugSource, string contentStartWith = "")
        {
            string sourceType;

            if (sourceTypes.ToString().Equals(Enum.GetName(typeof(SourceTypes), 1)))
            {
                sourceType = DebugPageSource;
            }
            else
            {
                sourceType = PageSource;
            }
            string attributeValue = string.Empty;
            string pattern        = pattern = string.Format(@"<meta name=""{0}""\scontent=""{1}(.*?)""", metaName, contentStartWith);

            try
            {
                Match match = Regex.Match(sourceType, pattern, RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    attributeValue = match.Groups[1].Value;
                }
            }
            catch { }
            return(attributeValue);
        }