首页 国内 国际 娱乐 体育 财经 科技 留学 健康 论坛 空间 汽车 文学 军事 爱墙 游戏 艺术 星座
短信 明星 数码 手机 美食 家居 股票 教育 公益 公益 旅游 彩票 商城 校园 奇闻 女性 房产 时尚

C#用正则表达式获取网页中制定位置的内容

string rl; 
WebRequest myReq 
= WebRequest.Create("http://weather.news.qq.com/inc/ss125.htm"); 
WebResponse myRes 
= myReq.GetResponse(); 
Stream resStream 
= myRes.GetResponseStream(); 
StreamReader sr 
= new StreamReader(resStream, Encoding.Default); 
StringBuilder sb 
= new StringBuilder(); 
while ((rl = sr.ReadLine()) != null

sb.Append(rl); 

string abc = "<td height=\"23\" align=\"center\"><img src=\"/images/tem1.gif\" width=\"57\" height=\"13\"></td><td height=\"23\" align=\"center\">"
string bcd = "<td height=\"23\" width=\"117\" background=\"/images/r_tembg5.gif\" align=\"center\">"
string regexStr = @"" + abc + "([^<]*)</td>"
Match mc 
= Regex.Match(sb.ToString(), regexStr, RegexOptions.IgnoreCase); 
string regexStr1 = @"" + bcd + "([^<]*)</td>"
Match mc1 
= Regex.Match(sb.ToString(), regexStr1, RegexOptions.IgnoreCase); 
this.Label1.Text = "气温 " + mc.Groups[1].Value + " " + mc1.Groups[1].Value; 
myRes.Close(); 
posted @ 2009-02-27 13:12  程序执着追随者  阅读(1059)  评论(1编辑  收藏  举报
友情链接
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置
你的位置