通过HttpWebRequest对象和HttpWebResponse对象从网页获取信息的一个实例,有兴趣的朋友可以看看。代码如下:
      
          static string GetWeatherInfo( string s1, string s2)
InBlock.gif        {
InBlock.gif             string ResponseText;
InBlock.gif             string text;
InBlock.gif             int startIndex;
InBlock.gif             int endIndex;
InBlock.gif            Uri url = new Uri( @"http://firetear.com/weather/lvweather.aspx");
InBlock.gif            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
InBlock.gif            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
InBlock.gif            req.Method = "Post";
InBlock.gif            StreamReader ReaderText = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
InBlock.gif            ResponseText = ReaderText.ReadToEnd();
InBlock.gif            res.Close();
InBlock.gif            startIndex = ResponseText.IndexOf(s1) + s1.Length;
InBlock.gif            endIndex = ResponseText.IndexOf(s2);
InBlock.gif            text = ResponseText.Substring(startIndex, endIndex - startIndex);
InBlock.gif            return text;
InBlock.gif        }
InBlock.gif
        private void Form1_Load(object sender, EventArgs e)
InBlock.gif        {
InBlock.gif            Label1.Text = GetWeatherInfo(@"g>", @"</");
InBlock.gif            Label2.Text = GetWeatherInfo(@"天气:", @",紫");
InBlock.gif        }
    
      效果图:
     
      
       如果想在网页中实现类似的功能,有更简单的方法,只需调用下面这段脚本即可,而且其返回的结果为一张图片,效果更好。
      
< img src ="http://firetear.com/weather/weather.aspx" border ="0" alt ="查询及定制我的天气预报信息" border ="0" />
      
       效果图: