WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
Byte[] pages = wc.DownloadData(url);
string pageHtml = Encoding.Default.GetString(pages);
Match charSetMatch = Regex.Match(pageHtml, "<meta([^<]*)charset=([^<]*)\"", RegexOptions.IgnoreCase | RegexOptions.Multiline);
string getcode = charSetMatch.Groups[2].Value;
pageHtml = Encoding.GetEncoding(getcode).GetString(pages);
Match title = Regex.Match(pageHtml, "<title>(.*)</title>");
this.NE_Title.Value = title.Groups[1].Value.ToString();//获得标题
string meatregex = "<meta" + @"\s+" + "name=\"description\"" + @"\s+" + "content=\"(?<content>[^\"" + @"\<\>" + "]*)\"";
Match description = Regex.Match(pageHtml, meatregex, RegexOptions.IgnoreCase | RegexOptions.Multiline);
Label1.Text = description.Groups[1].Value;
评论