明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
  博客园  :: 首页  :: 管理
public ArrayList GetWeather(string code)
{
/*
[0]"今日天气"string
[1]"北京"string
[2]"<img src=http://image2.sina.com.cn/dy/weather/images/figure/leizhenyu_big.gif width=45 height=45 alt=雷阵雨>"string
[3]"雷阵雨"string
[4]"29℃~21℃"string
[5]"2006年7月27日-28日"string
[6]" 风力:小于3级"string
[7]"空气质量:良 "string
[8]"紫外线强度:弱 "string
*/
string html = string.Empty;
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
{
throw new Exception("访问地址出错~~~");
}
int count = html.Length;
int starIndex = html.IndexOf("<table ",0,count-1);
int endIndex = html.IndexOf("</table>",starIndex,count-starIndex-1);
html = html.Substring(starIndex,endIndex-starIndex+8);
html = Regex.Replace(html,"<br/>|</td>","|");
html = Regex.Replace(html,"<[^img][^>]*>","");
html = Regex.Replace(html,"\t|\r|\n","");
string [] strWeather = html.Split('|');
ArrayList array = new ArrayList();
foreach(string strTemp in strWeather)
{
if(strTemp != "")
array.Add(strTemp);
}
return array;
}