ASP.NET数据传递:获取META信息

ASP.NET中数据传递:获取用Meta传递的数据:
 1public static string GetMeta(string strFullUrl, string MateName)
 2{
 3//strFullUrl需要有Http前缀
 4HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strFullUrl);
 5myRequest.KeepAlive = false;
 6myRequest.Timeout = 30000;
 7myRequest.ReadWriteTimeout = 30000;
 8string content = "";
 9string strError = "";
10try
11{
12HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
13StreamReader myReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
14//返回内容存放于content中
15content = myReader.ReadToEnd();
16myReader.Close();
17myResponse.Close();
18}

19catch (Exception ex)
20{
21strError = ex.Message.ToString();
22}

23
24//分析返回信息中的<meta>标志中content=的内容
25RegexOptions RxOptions = RegexOptions.IgnoreCase;
26string StrToGetMate =
27@"<meta Name=\""{0}\"" content[\s]?=[\s\""\']+(.*?)[\""\']+.*?>";
28Regex myRx = new Regex(string.Format(StrToGetMate, MateName), RxOptions);
29Match myMt = myRx.Match(content);
30if (null != myMt)
31{
32//有匹配内容
33content = myMt.Groups[1].ToString();
34}

35//返回内容
36if (strError.Length > 0)
37{
38return strError;
39}

40else
41{
42return content;
43}

44}

posted @ 2008-05-09 14:55 永远燃烧 阅读(43) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-07-21 23:21 编辑过