《筛选网页信息获取天气预报》由会员分享,可在线阅读,更多相关《筛选网页信息获取天气预报(3页珍藏版)》请在金锄头文库上搜索。
1、/ / 天气预报/ private static void GetTian7OnlineWeather()tryWebRequest wreq = WebRequest.Create(http:/ wresp = (HttpWebResponse)wreq.GetResponse();string HTML = ;Stream s = wresp.GetResponseStream();StreamReader objReader = new StreamReader(s, System.Text.Encoding.Default);HTML = objReader.ReadToEnd();i
2、f (HTML = null | HTML = )return;string AllWeather = , lowest1, lowest2, highest1, highest2, morning1, morning2, afternoon1, afternoon2, night1, night2;int start, stop;/HTML=HTML.ToLower();/取得城市天气的地址start = HTML.IndexOf(徐州, 0);start = HTML.IndexOf(href=, start);stop = HTML.IndexOf(, start + 6);string
3、 href = HTML.Substring(start + 6, stop - start - 6);/获取页面数据href = http:/ + href;wreq = WebRequest.Create(href);wresp = (HttpWebResponse)wreq.GetResponse();HTML = ;s = wresp.GetResponseStream();objReader = new StreamReader(s, System.Text.Encoding.Default);HTML = objReader.ReadToEnd();if (HTML = null
4、| HTML = )return;HTML = HTML.ToLower(); start = HTML.IndexOf(最低温度, 0);start = HTML.IndexOf(, start);stop = HTML.IndexOf(, start);lowest1 = HTML.Substring(start + 3, stop - start - 3);start = HTML.IndexOf(, stop);stop = HTML.IndexOf(, start);lowest2 = HTML.Substring(start + 3, stop - start - 3);start
5、 = HTML.IndexOf(最高温度, 0);start = HTML.IndexOf(, start);stop = HTML.IndexOf(, start);highest1 = HTML.Substring(start + 3, stop - start - 3);start = HTML.IndexOf(, stop);stop = HTML.IndexOf(, start);highest2 = HTML.Substring(start + 3, stop - start - 3);start = HTML.IndexOf(上午, 0);start = HTML.IndexOf
6、(title=, start);stop = HTML.IndexOf(, start + 7);morning1 = HTML.Substring(start + 7, stop - start - 7);start = HTML.IndexOf(title=, start);stop = HTML.IndexOf(, start + 7);morning2 = HTML.Substring(start + 7, stop - start - 7);start = HTML.IndexOf(下午, 0);start = HTML.IndexOf(title=, start);stop = H
7、TML.IndexOf(, start + 7);afternoon1 = HTML.Substring(start + 7, stop - start - 7);start = HTML.IndexOf(title=, start);stop = HTML.IndexOf(, start + 7);afternoon2 = HTML.Substring(start + 7, stop - start - 7);start = HTML.IndexOf(晚上, 0);start = HTML.IndexOf(title=, start);stop = HTML.IndexOf(, start
8、+ 7);night1 = HTML.Substring(start + 7, stop - start - 7);start = HTML.IndexOf(title=, start);stop = HTML.IndexOf(, start + 7); night2 = HTML.Substring(start + 7, stop - start - 7);lowest1.Replace(, );lowest1.Replace(, );highest1 = highest1.Replace(, );highest1 = highest1.Replace(, );lowest2.Replace
9、(, );lowest2.Replace(, );highest2 = highest1.Replace(, );highest2 = highest1.Replace(, );AllWeather = 今日天气 + lowest1 + + highest1 + + morning1 + + afternoon1 + + night1 + ;AllWeather = AllWeather + 明日天气 + lowest2 + + highest2 + + morning2 + + afternoon2 + + night2 + ;AllWeather = AllWeather.Replace(
10、AllWeather = + AllWeather + ;string path = OnlineWeather.xml;FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);StreamWriter writer = new StreamWriter(fs, Encoding.Default);writer.WriteLine(AllWeather);writer.Close();fs.Close();catchSystem.Console.WriteLine(网络连接失败!);System.Console.ReadLine();return;本文来自 CSDN 博客,转载请标明出处:http:/