天气预报代码html 天气预报代码大全

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.Data.SqlClient;

using System.Net;

using System.IO;

using System.Collections;

/// &<summary&>

/// Weather 的摘要说明

/// &</summary&>

public class Weather

{

public Weather()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public static string ConvertCodeByCity(string City)

{

string Code = "";

switch (City)

{

case "北京":

Code = "110100";

break;

default:

break;

}

return Code;

}

public static ArrayList GetWeather(string code)

{

/*

[0] "北京 "string

[1] "雷阵雨 "string

[2] "9℃" string

[3] "29℃"string

[4] "小于3级"string

*/

string html = "";

try

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("://weather.sina.cn/iframe/weather/" + code + "_w.html ");

request.Method = "Get";

//request.Timeout = 1;

request.ContentType = "lication/x--form-urlencoded ";

WebResponse response = request.GetResponse();

Stream s = response.GetResponseStream();

StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));

html = sr.ReadToEnd();

s.Close();

sr.Close();

}

catch (Exception err)

{

throw new Exception("访问地址出错~~~ ");

}

int count = html.Length;

int starIndex = html.IndexOf("&<table ", 0, count);

int endIndex = html.IndexOf("&</table&>", starIndex, count - starIndex);

html = html.Substring(starIndex, endIndex - starIndex + 8);

//得到城市

int cityStartIndex = html.IndexOf("&<b&>", 0, html.Length);

int cityEndIndex = html.IndexOf("&</b&>", 0, html.Length);

string City = html.Substring(cityStartIndex + 3, cityEndIndex - cityStartIndex - 3);

//得到天气

int weatherStartIndex = html.IndexOf("&<b&>", cityEndIndex);

int weatherEndIndex = html.IndexOf("&</b&>", weatherStartIndex);

string Weather = html.Substring(weatherStartIndex + 3, weatherEndIndex - weatherStartIndex - 3);

//得到温度

int temperatureStartIndex = html.IndexOf("&<b", weatherEndIndex);

int temperatureEndIndex = html.IndexOf("&</b&>", weatherEndIndex + 3);

string Temperature = html.Substring(temperatureStartIndex + 21, temperatureEndIndex - temperatureStartIndex - 21);

int int1 = Temperature.IndexOf("℃", 0);

int int2 = Temperature.IndexOf("~", 0);

int int3 = Temperature.IndexOf("℃", int2);

string MinTemperature = Temperature.Substring(int2 + 1, int3 - int2);

string MaxTemperature = Temperature.Substring(0, int2 - int1 + 2);

//得到风力

int windforceStartIndex = html.IndexOf("风力:", temperatureEndIndex);

int windforceEndIndex = html.IndexOf("&<br&>", windforceStartIndex);

string Windforce = html.Substring(windforceStartIndex + 3, windforceEndIndex - windforceStartIndex - 3);

if (Windforce.Contains("小于") &&&& (!Windforce.Contains("等于"))) //判断风力是否含有"小于"或"小于等于"字样将,如果有的话,将其替换为2-

{

//Windforce = Windforce.Replace("小于", "2-");

string strWindforce = Windforce.Substring(2, Windforce.Length - 3);

int minWindforce = Int32.Parse(strWindforce) - 1;

Windforce = Windforce.Replace("小于", minWindforce.ToString() + "-");

}

else if (Windforce.Contains("小于等于"))

{

string strWindforce = Windforce.Substring(4, Windforce.Length - 5);

int minWindforce = Int32.Parse(strWindforce) - 1;

Windforce = Windforce.Replace("小于等于", minWindforce.ToString() + "-");

}

ArrayList al = new ArrayList();

al.Add(City);

al.Add(Weather);

al.Add(MinTemperature);

al.Add(MaxTemperature);

al.Add(Windforce);

return al;

}

}

百度首页的天气是怎么调出来的,代码哪里下载。

1.左端点:近十日最低温度;2.右端点:近十日最高温度;3.有圆点的部分:当前温度;4.整体长条长度:温差. (长表示此天温差大, 短则表示温差小);颜色部分:温度越高, 颜色就越红. 反之,温度越低,颜色就越蓝甚至紫.

我想知道大连未来五天的天气,最好是发过来你信息的来源的

首先登入百度账号

将鼠标移动到天气上,就会出现未来几天天气的详细情况,点击右上角的设置

就可以选择省份

接着选择城市,一般省会在第一个,其他的城市按照开头名字的第一个字母排序

可以勾选极端天气提醒,在出现极端天气的时候,登入百度首页就可以收到提醒

然后点击保存

就可以看到首页天气设置好了

代码看中国天气网里面的插件

c#窗体程序中怎么获取到从接口中得到的信息?天气预报://m.weather.cn/data/101230101.html

15日星期三 多云转阵雨高温:12℃低温:6℃南风4-5级转东北风5-6级16日星期四

晴高温:14℃低温:5℃北风5-6级17日星期五

晴高温:16℃低温:7℃西南风4-5级18日星期六

晴高温:17℃低温:8℃南风5-6级19日星期日

多云转中雨高温:20℃低温:13℃微风20日星期一

中雨转晴高温:22℃低温:12℃微风转北风3-4级

你这个不是接口,只是个网页地址。

我找到另外一个天气预报的接口:

://.webxml.cn/WebServices/WeatherWebService.asmx

只要在项目中添加Web引用:

按照这个做:

然后人就可以实例化这个对象:

调用对应的方法就可以获取接口中的信息了。

直接在IE或其它浏览器中打开这接口网址:

://.webxml.cn/WebServices/WeatherWebService.asmx

可以看到那些方法的使用说明。

还是不会就不应该了。为了这15分,可以加我好友再问。

本文链接:http://www.frpt.cn/tqyb/14238.html
免责声明:文章由网友分享发布,并不意味本站赞同其观点,文章内容仅供参考。此文如侵犯到您的合法权益,请联系我们立刻删除。