//提供一段天气预报的源码,仅供参考,摘自网络
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;namespace ReportWeatherDemo
{
    class CityWeather
    {
        //-- 将此处的页面地址替换为相应的地址就行了,可以登陆 www.cma.gov.cn 查询到相应的城市
        //string pageUrl = "http://www.cma.gov.cn/tqyb/weatherdetail/57496.html";  //鄂州
        string pageUrl = "http://www.cma.gov.cn/tqyb/weatherdetail/58367.html";    //上海        //-- 用于存储抓取出来的地点的名称
        string dd = string.Empty;        //-- 天气状况
        string tqgk = string.Empty;        //-- 气温
        string qw = string.Empty;        //-- 风力/风向
        string fxfl = string.Empty;        public string GetWeatherInfo()
        {
            WebClient wc = new WebClient();
            wc.Credentials = CredentialCache.DefaultCredentials;            Byte[] bt = wc.DownloadData(@pageUrl);            string result = Encoding.Default.GetString(bt);            if (result.Length <= 0)
            {
                System.Windows.Forms.MessageBox.Show("未找到指定的城市天气信息!");
                result = "";
            }            int pos = result.IndexOf("<div class=\"font01\">3天预报&nbsp;&nbsp;&nbsp;</div>");            if (pos > 0)
                result = "未找到该城市的天气预报!";
            else
            {
                pos = result.IndexOf("<div class=\"font01\">3天预报");                result = result.Substring(pos, result.IndexOf("穿衣指数") - pos);                pos = result.IndexOf("&nbsp;&nbsp;&nbsp;") + 18;
                dd = result.Substring(pos, result.IndexOf("</") - pos);                pos = result.IndexOf("天气概况");
                result = result.Substring(pos, result.IndexOf("<!--<tr>") - pos);                pos = result.IndexOf("<td width=\"75\"");
                result = result.Substring(pos);                pos = result.IndexOf(">");
                tqgk = result.Substring(pos + 1, result.IndexOf("</td>") - pos - 1);                result = result.Substring(result.IndexOf("气 温"));
                pos = result.IndexOf("cn\">") + 4;                qw = result.Substring(pos, result.IndexOf("℃</td>") - pos + 1);                result = result.Substring(result.IndexOf("风向/风力</td>"));
                result = result.Substring(result.IndexOf("<td"));                pos = result.IndexOf("cn\">") + 4;                fxfl = result.Substring(pos, result.IndexOf("</td") - pos);                tqgk = "今日天气:" + tqgk.Replace(" ", "");
                qw = qw.Replace(" ", "");                //qw = "最高温度:" + qw.Replace("/", " 最低温度:");
                qw = "最高温度:" + qw.Replace("/", ",最低温度:");
                fxfl = "风向/风力:" + fxfl.Replace(" ", "");                result = dd + "," + tqgk + "," + qw + "," + fxfl;            }            return result;
        }
    }
}

解决方案 »

  1.   

    正则表达式,字符串运算。或者dom解析。
    最后一种方式速度是最慢的,但它是最直观的。
      

  2.   

    就是要把 http://ditu.google.cn/maps?f=q&hl=zh-CN&geocode=&q=%E9%83%91%E5%B7%9E+%E9%A4%90%E5%8E%85&sll=37.649034,106.435547&sspn=31.697307,59.414062&ie=UTF8&view=text
    网址下的 例如 郑州颐顺轩餐饮有限公司‎
    河南省郑州市未来路65号‎ - 0371-65932299
    ‎ 
    米兰庐西餐厅‎
    郑州二七区北二七路106号和邦大厦南2楼‎ - 0371-6263355
    .
    .
    .
    取出来