求三天的天气预报代码

天上下雨 2011-03-10 03:48:00
求三天的天气预报代码,要求可以传递城市名称的,而不是自己选择的那种~~~
...全文
100 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
RUNBEAR 2011-03-11
  • 打赏
  • 举报
回复
支持楼上,GOOGLE好多API可以调用的。
天上下雨 2011-03-11
  • 打赏
  • 举报
回复
谢谢各位了,用google的API已经成功了~~
但后来用了其他的方法,但是还是学到了不少,谢谢拉~~~
mohugomohu 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 dongxinxi 的回复:]

Google API就可以了,给你一个只取一天的例子,要取三天的读取后续的结点就行了,这是2.0的,你也可以用Linq读
C# code

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Net;
using System.Xml;

private const string _req……
[/Quote]mark
linuxjava01 2011-03-11
  • 打赏
  • 举报
回复
Google的那个很强大。
andy_dyg 2011-03-11
  • 打赏
  • 举报
回复
www.webxmml.com.cn

从这里调用方法就可以了。

  • 打赏
  • 举报
回复

<?xml version="1.0" ?>
- <xml_api_reply version="1">
- <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
- <forecast_information>
<city data="Beijing, Beijing" />
<postal_code data="Beijing" />
<latitude_e6 data="" />
<longitude_e6 data="" />
<forecast_date data="2011-03-10" />
<current_date_time data="2011-03-10 22:00:00 +0000" />
<unit_system data="US" />
</forecast_information>
- <current_conditions>
<condition data="Clear" />
<temp_f data="61" />
<temp_c data="16" />
<humidity data="Humidity: 12%" />
<icon data="/ig/images/weather/sunny.gif" />
<wind_condition data="Wind: NW at 13 mph" />
</current_conditions>
- <forecast_conditions>
<day_of_week data="Thu" />
<low data="30" />
<high data="55" />
<icon data="/ig/images/weather/sunny.gif" />
<condition data="Clear" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Fri" />
<low data="32" />
<high data="53" />
<icon data="/ig/images/weather/sunny.gif" />
<condition data="Clear" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Sat" />
<low data="41" />
<high data="68" />
<icon data="/ig/images/weather/mostly_sunny.gif" />
<condition data="Mostly Sunny" />
</forecast_conditions>
- <forecast_conditions>
<day_of_week data="Sun" />
<low data="32" />
<high data="57" />
<icon data="/ig/images/weather/mostly_sunny.gif" />
<condition data="Partly Sunny" />
</forecast_conditions>
</weather>
</xml_api_reply>
  • 打赏
  • 举报
回复
Google API就可以了,给你一个只取一天的例子,要取三天的读取后续的结点就行了,这是2.0的,你也可以用Linq读

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Net;
using System.Xml;

private const string _requestURL = @"http://www.google.com/ig/api?weather=";

#region "Event Handlers"
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
string city = Request.QueryString["City"] ?? "Beijing";
ltCity.Text = "Today in " + city;
XmlDocument xmlWeather = GoogleWeatherAPI_Parser(_requestURL + city);
if (xmlWeather != null)
{
XmlNode current_conditions = xmlWeather.SelectSingleNode("xml_api_reply/weather/current_conditions");
ltTemperature.Text = current_conditions.SelectSingleNode("temp_f").Attributes["data"].InnerText;
imgWeather.ImageUrl = string.Format("{0}{1}", "http://www.google.com", current_conditions.SelectSingleNode("icon").Attributes["data"].InnerText);
}
}

/// <summary>
/// Request the weather xml result from the specified URL by GoogleWeatherAPI
/// </summary>
/// <param name="baseUrl"></param>
/// <returns></returns>
private static XmlDocument GoogleWeatherAPI_Parser(string baseUrl)
{
HttpWebRequest GWP_Request;
HttpWebResponse GWP_Response = null;
XmlDocument GWP_XMLdoc = null;
try
{
GWP_Request = (HttpWebRequest)WebRequest.Create(string.Format(baseUrl));
GWP_Request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; en-US; Trident/5.0)";
GWP_Response = (HttpWebResponse)GWP_Request.GetResponse();
GWP_XMLdoc = new XmlDocument();
GWP_XMLdoc.Load(GWP_Response.GetResponseStream());
}
finally
{
GWP_Response.Close();
}
return GWP_XMLdoc;
}
#endregion
天上下雨 2011-03-10
  • 打赏
  • 举报
回复
现在的好多都是城市已经固定了的,怎么才能找到不固定的呢?
flyerwing 2011-03-10
  • 打赏
  • 举报
回复
中国气象网好象很多站子都是有气象服务的了.
天上下雨 2011-03-10
  • 打赏
  • 举报
回复
关键是这个城市是不定的,从数据库中取得城市名,然后显示这个城市3天的天气预报~
小阳 2011-03-10
  • 打赏
  • 举报
回复
直接嵌入天气预报就OK啦

<iframe src="http://m.weather.com.cn/m/pn11/weather.htm?id=101010100T " style="border:1px #E6E2ED solid;padding-top:5px;padding-left:5px;" width="490" height="59" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>


你想定制哪里就把id改一下,这里是定制北京的
沙伽more 2011-03-10
  • 打赏
  • 举报
回复
WCF
shine_fly 2011-03-10
  • 打赏
  • 举报
回复
直接找API

7,765

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧