Example #1
0
        private static System.Text.Encoding getEncoding(string url)
        {
            string hTMLContent = HttpCollects.GetHTMLContent(url, System.Text.Encoding.UTF8, "charset\\b\\s*=\\s*(?<charset>[a-zA-Z\\d|-]*)");
            Regex  regex       = new Regex("charset\\b\\s*=\\s*(?<charset>[a-zA-Z\\d|-]*)");

            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            if (regex.IsMatch(hTMLContent))
            {
                foreach (Match match in regex.Matches(hTMLContent))
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(match.Groups["charset"].Value))
                        {
                            encoding = System.Text.Encoding.GetEncoding(match.Groups["charset"].Value);
                            if (encoding != null)
                            {
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(encoding);
        }
Example #2
0
 public static string GetHTMLContent(string url)
 {
     return(HttpCollects.GetHTMLContent(url, null, null));
 }
Example #3
0
 public static string GetHTMLContent(string url, string endRegexString)
 {
     return(HttpCollects.GetHTMLContent(url, null, endRegexString));
 }