通过HttpWebRequest对象和HttpWebResponse对象从网页获取信息的一个实例,有兴趣的朋友可以看看。代码如下:
      
          static string GetWeatherInfo( string s1, string s2)
        {
             string ResponseText;
             string text;
             int startIndex;
             int endIndex;
            Uri url = new Uri( @"http://firetear.com/weather/lvweather.aspx");
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            req.Method = "Post";
            StreamReader ReaderText = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
            ResponseText = ReaderText.ReadToEnd();
            res.Close();
            startIndex = ResponseText.IndexOf(s1) + s1.Length;
            endIndex = ResponseText.IndexOf(s2);
            text = ResponseText.Substring(startIndex, endIndex - startIndex);
            return text;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Label1.Text = GetWeatherInfo(@"g>", @");
            Label2.Text = GetWeatherInfo(@"天气:", @",紫");
        }
    
      效果图:
     
      
       如果想在网页中实现类似的功能,有更简单的方法,只需调用下面这段脚本即可,而且其返回的结果为一张图片,效果更好。
      
< img src ="http://firetear.com/weather/weather.aspx" border ="0" alt ="查询及定制我的天气预报信息" border ="0" />
      
       效果图: