筛选网页信息获取天气预报

上传人:mg****85 文档编号:34082103 上传时间:2018-02-20 格式:DOC 页数:3 大小:33.50KB
返回 下载 相关 举报
筛选网页信息获取天气预报_第1页
第1页 / 共3页
筛选网页信息获取天气预报_第2页
第2页 / 共3页
筛选网页信息获取天气预报_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《筛选网页信息获取天气预报》由会员分享,可在线阅读,更多相关《筛选网页信息获取天气预报(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:/

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号