All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
[delphi语法3]声明delphi几个常用语句方法
C#中控制语句if的使用
SQL,标量值函数的调用_mssql学习_编程技术
Asp.net数据库操作类,c#_[Asp.Net教程]
PHP将汉字转换拼音_[PHP教程]
javascript:世界上误解最深的语言_JavaScript技术_编程技术
c#中GDI+图形图像:GDI+中的椭圆和弧使用方法
技巧:ASP.Net,2.0,发送邮件的代码_.net资料_编程技术
c#中一维数组的声明
在ASP.NET2.0中创建Web应用程序主题_[Asp.Net教程]
Reading number is top 10 pictures
Born After 90 Beijing sports university campus flower photos2
Tie a large font of mouse
From China fortress sora aoi2
A beautiful girl to bud2
每天进步一点点
The beginning and end
西游日记1
Beautiful vacuum girl1
Sora aoi possession of boudoir1
张家界的玻璃桥
Download software ranking
WebService在.NET中的实战应用教学视频 → 第1集
matrix1
电车之狼R
实战黑客不求人
Unix video tutorial8
White deer villiage
Unix video tutorial2
功夫熊猫2(上集)
Proficient in Eclipse
Call Of Duty2
归海一刀 published in(发表于) 2014/1/30 1:57:45 Edit(编辑)
网页中添加新浪天气预报的几种方法_[Asp.Net教程]

网页中添加新浪天气预报的几种方法_[Asp.Net教程]

网页中添加新浪天气预报的几种方法_[Asp.Net教程]
1.利用新浪提供给的iframe直接嵌入,这种方式非常的简单,但是却没有交互性。代码如下:
2.抓取当天的天气,以指定格式输出。
涉及的核心代码如下:

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("http://weather.sina.com.cn/iframe/weather/" + code + "_w.html ");
request.Method = "Get";
//request.Timeout = 1;
request.ContentType = "application/x-www-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("
int endIndex = html.IndexOf("
", starIndex, count - starIndex);
html = html.Substring(starIndex, endIndex - starIndex + 8);

//得到城市
int cityStartIndex = html.IndexOf("", 0, html.Length);
int cityEndIndex = html.IndexOf("
", 0, html.Length);
string City = html.Substring(cityStartIndex + 3, cityEndIndex - cityStartIndex - 3);


//得到天气
int weatherStartIndex = html.IndexOf("", cityEndIndex);
int weatherEndIndex = html.IndexOf("
", weatherStartIndex);
string Weather = html.Substring(weatherStartIndex + 3, weatherEndIndex - weatherStartIndex - 3);

//得到温度

int temperatureStartIndex = html.IndexOf(" int temperatureEndIndex = html.IndexOf("", 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("
", 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;
}
这里涉及到一个ConvertCode类,它的作用是用于把城市转换为对应的全国统一的编码,


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.