- public static string GetInnerHtml(string url)
- {
- WebClient wc = new WebClient();
- wc.Credentials = CredentialCache.DefaultCredentials;
- byte[] htmlbuffer = wc.DownloadData(url);
- Regex regex = new Regex("charset\\s*=\\s*[\\W]?\\s*([\\w-]+)", RegexOptions.IgnoreCase);
- string content = Encoding.Default.GetString(htmlbuffer);
- Encoding encoding = Encoding.Default;
- if (regex.IsMatch(content))
- {
- encoding = Encoding.GetEncoding(regex.Match(content).Groups[1].Value.Trim());
- content = encoding.GetString(htmlbuffer);
- }
- else
- {
- content = Encoding.Default.GetString(htmlbuffer);
- }
- return content;
- }
沒有留言:
張貼留言