从中央气象台抓取天气预报
这几天郑州下雪,一直盼望晴天的到来,于是关注天气情况.
可以Google一下:tq 郑州
如今写了个抓取中央气象台的天气预报(http://www.tq121.com)![](/Emoticons/74_74.gif)
public string GetWeather(string url)
{
string weacherhtml=String.Empty;
HttpWebRequest rt=null;
HttpWebResponse rs=null;
Stream stream=null;
StreamReader sr=null;
try
{
rt=(HttpWebRequest)WebRequest.Create(url);
rs=(HttpWebResponse)rt.GetResponse();
stream=rs.GetResponseStream();
sr=new StreamReader(stream,System.Text.Encoding.Default);
weacherhtml=sr.ReadToEnd();
}
catch(Exception ee)
{
Response.Write("<script>alert('发生异常')</script>");
}
finally
{
sr.Close();
stream.Close();
rs.Close();
}
![](/Images/OutliningIndicators/InBlock.gif)
int start=weacherhtml.IndexOf("郑州");
int end=weacherhtml.IndexOf("隐私保护");
![](/Images/OutliningIndicators/InBlock.gif)
return weacherhtml.Substring(start,end-start);
![](/Images/OutliningIndicators/InBlock.gif)
}
别的城市天气情况请调用相应的URL,以及修改城市名称.
可以Google一下:tq 郑州
如今写了个抓取中央气象台的天气预报(http://www.tq121.com)
![](/Emoticons/74_74.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
别的城市天气情况请调用相应的URL,以及修改城市名称.