使用Yahoo的公开API做天气预报
2008-08-22 10:09
423 查看
location.href="http://blog.moozi.net/read-131.html";
在Yahoo的Developer Network
http://developer.yahoo.com/weather/
详细地介绍了Yahoo天气预报的API调用方法,这里用C#来实现,本文仅作为抛砖,其它的应用由网友们自由发挥
首先了解Yahoo Weather Api的RSS Response格式:
Console Codes
using System;
using System.Xml;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
XmlDocument document = new XmlDocument();
document.Load("http://xml.weather.yahoo.com/forecastrss?p=CHXX0131");
XmlNodeList nodes = document.GetElementsByTagName("forecast",
@"http://xml.weather.yahoo.com/ns/rss/1.0");
foreach (XmlNode node in nodes)
{
Console.WriteLine("日期:{0},星期:{1},天气:{2},温度:{3}°C 至 {4}°C",
node.Attributes["date"].InnerText,
node.Attributes["day"].InnerText,
node.Attributes["text"].InnerText,
FToC(int.Parse(node.Attributes["low"].InnerText)),
FToC(int.Parse(node.Attributes["high"].InnerText)));
}
}
private static string FToC(int f)
{
return Math.Round((f - 32) / 1.8,1).ToString();
}
}
}
简单的实现了天气预报的功能了,这里调用的是河北唐山的天气,需要其它地区的天气可以这里查找代码
http://weather.yahoo.com/China/CHXX/regional.html
在Yahoo的Developer Network
http://developer.yahoo.com/weather/
详细地介绍了Yahoo天气预报的API调用方法,这里用C#来实现,本文仅作为抛砖,其它的应用由网友们自由发挥
首先了解Yahoo Weather Api的RSS Response格式:
Console Codes
using System;
using System.Xml;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
XmlDocument document = new XmlDocument();
document.Load("http://xml.weather.yahoo.com/forecastrss?p=CHXX0131");
XmlNodeList nodes = document.GetElementsByTagName("forecast",
@"http://xml.weather.yahoo.com/ns/rss/1.0");
foreach (XmlNode node in nodes)
{
Console.WriteLine("日期:{0},星期:{1},天气:{2},温度:{3}°C 至 {4}°C",
node.Attributes["date"].InnerText,
node.Attributes["day"].InnerText,
node.Attributes["text"].InnerText,
FToC(int.Parse(node.Attributes["low"].InnerText)),
FToC(int.Parse(node.Attributes["high"].InnerText)));
}
}
private static string FToC(int f)
{
return Math.Round((f - 32) / 1.8,1).ToString();
}
}
}
简单的实现了天气预报的功能了,这里调用的是河北唐山的天气,需要其它地区的天气可以这里查找代码
http://weather.yahoo.com/China/CHXX/regional.html
相关文章推荐
- 【转】 使用Yahoo的公开API做天气预报
- 【转】 使用Yahoo的公开API做天气预报
- 使用jQuery、Yahoo API和HTML5的geolocation来开发一个天气预报web应用
- 使用jQuery、Yahoo API和HTML5的geolocation来开发一个天气预报web应用
- 使用 C# 和 Yahoo API 做天气预报
- 使用jQuery、Yahoo API和HTML5的geolocation来开发一个天气预报web应用
- 利用YAHOO公开API做天气预报Web服务
- Web Service学习笔记:利用YAHOO公开API做天气预报Web服务
- 使用jQuery、Yahoo API和HTML5的geolocation来开发一个天气预报web应用
- iPhone开发技巧之环境篇--- 使用非公开的API
- 使用Google Weather API 制作天气预报应用
- 使用Google Weather API查询天气预报
- 使用Yahoo API获取雅虎的证券股票数据接口(时价 K线等)
- Android使用XmlPullParser解析XML以及天气预报信息api使用
- 如何使用 Yahoo! Finance stock API 获取股票数据
- Java学习之利用yahoo weather api 获取天气预报
- Android上实现一个简单的天气预报APP(十四) 使用百度API定位城市
- 如何使用 Yahoo! Finance stock API 获取股票数据
- 使用Google Weather API查询天气预报
- 使用 IBM OmniFind Yahoo! Edition REST API