点击回首页
我的浏览记录 | | 帮助?
当前位置:

源码截图

源码目录树

当前路径:LetSearch/App-Code/WeatherInfo.cs     using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;

//该源码下载自www.51aspx.com(51aspx.com)


/// <summary>
/// WeatherInfo 的摘要说明
/// </summary>
public class WeatherInfo
{
	public WeatherInfo()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
    }
            /// <summary>
    /// 获取指定城市代码的城市天气
    /// </summary>
    /// <param name="CityCode">城市代码</param>
    /// <returns>天气信息</returns>
    public static Weather GetCurrentWeather(string CityCode)
    {
        try
        {
            Uri myUri = new Uri("http://weather.news.qq.com/inc/ss" + CityCode + ".htm");

            HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(myUri);

            myWebRequest.Method = "GET";

            HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

            StreamReader reader = new StreamReader(myWebResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));

            byte[] buffer = System.Text.Encoding.GetEncoding("GB2312").GetBytes(reader.ReadToEnd());
            String HTML = System.Text.Encoding.GetEncoding("GB2312").GetString(buffer).Trim();
            String temp = "";
            int start, stop;

            start = HTML.IndexOf("</style>", 0, HTML.Length);

            stop = HTML.IndexOf("<script>", 0, HTML.Length);
            temp = HTML.Substring(start, stop - start);
            Regex regex = new Regex("<[^>]*>");
            string[] ss = regex.Split(temp);
            string t = "";
            foreach (string p in ss)
                if (p.Trim().Length > 0)
                    t += p + "/";
            string[] sss = t.Split('/');
            Weather weather = new Weather();
            if (sss.Length > 0) weather.City = sss[0];
            if (sss.Length > 1) weather.TodayWeather = sss[1];
            if (sss.Length > 2) weather.WenDu = sss[2];
            if (sss.Length > 3) weather.FengLi = sss[3];
            if (sss.Length > 4) weather.ZiWaiXian = sss[4];
            if (sss.Length > 5) weather.KongQi = sss[5];
            reader.Close();
            myWebResponse.Close();
            return weather;
        }
        catch
        {
            Weather w = new Weather();
            w.City = "-1";
            return w;
        }
	}
}

/// <summary>
/// 天气信息类
/// </summary>
public class Weather
{
    public string City;//城市
    public string TodayWeather;//天气
    public string WenDu;//温度
    public string FengLi;//风力
    public string ZiWaiXian;//紫外线
    public string KongQi;//空气
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:4000410510
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
在线客服
分享该页面
关闭侧边栏