如果读取最简单的天气信息?

liguokun 2011-10-18 10:13:57
想在首页的上面显示广州的天气信息,最简单的那种:31度,微风,这样就OK了。有哪位有最简单的方法,谢谢了·!
用asp.net+C#实现的。
...全文
234 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq4004229 2011-10-18
  • 打赏
  • 举报
回复
调用JS或者webserivce就可以了
诺维斯基 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jss122414092 的回复:]
C# code



<iframe src="http://www.zzsky.cn/code/weather/weather1.htm"

width="170" height="15" marginwidth="0" marginheight="0" hspace="0"

vspace="0" frameborder="0" scrolling="no"></iframe>


放……
[/Quote]

不错,果然可以。
YnSky 2011-10-18
  • 打赏
  • 举报
回复
.net天气预报代码调用大全
265天气根据IP自动获得当地的天气情况
<iframe src="http://weather.265.com/weather.htm" width="168" height="54" frameborder="no" border="0" marginwidth="0&quoat; marginheight="0" scrolling="no"></iframe>
<BR>

QQ天气预报代码(一)
<iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://minisite.qq.com/Weather/news_new.html" allowTransparency="true"></iframe>
<BR>

QQ天气预报代码(二)
代码 :<IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC='http://weather.qq.com/inc/ss211.htm'></IFRAME>
<BR>
新浪天气预报代码
<IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src="http://news.sina.com.cn/iframe/weather/420101.html"></IFRAME>
<iframe width="260" height="195" frameborder=0 border=0 scrolling=no src="http://weather.265.com/weather.htm"></iframe>
效果图:
fjasdlkgh 2011-10-18
  • 打赏
  • 举报
回复
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx
调用一下这个网站的Webservice
http://www.cnblogs.com/ServerMaintaining/archive/2010/11/08/1871473.html打开这个链接,是WindowsForm程序,但是asp.net的获取天气预报信息方式和他是一样的,就自己改改显示方式就行。
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyWeather
{
public class WeatherClass
{
/// <summary>
/// 取得支持的城市,若高速缓存中不存在则直接调用服务读取
/// 获得本天气预报Web Services支持的洲、国内外省份和城市信息
/// 输入参数:无;返回:DataSet 。DataSet.Tables(0) 为支持的洲和国内省份数据,
/// DataSet.Tables(1) 为支持的国内外城市或地区数据。
/// DataSet.Tables(0).Rows(i).Item("ID") 主键对应 DataSet.Tables(1).Rows(i).Item("ZoneID") 外键。
/// Tables(0):ID = ID主键,Zone = 支持的洲、省份;
/// Tables(1):ID 主键,ZoneID = 对应Tables(0)ID的外键,Area = 城市或地区,AreaCode = 城市或地区代码。
/// </summary>
/// <returns>返回记录集</returns>
public static DataSet getSupportDataSet()
{
DataSet ds = (DataSet)HttpContext.Current.Cache["dataSetCache"];//从高速缓存中读取记录集
if (ds == null)//若无此缓存
{
cn.com.webxml.www.WeatherWebService Weather = new MyWeather.cn.com.webxml.www.WeatherWebService();
ds = Weather.getSupportDataSet();
HttpContext.Current.Cache.Insert("dataSetCache", ds, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);//设置缓存
}
return ds;
}
/// <summary>
/// 根据城市代码取得城市天气,有高速缓存
/// </summary>
/// <param name="cityCode">城市代码</param>
/// <returns>返回天气字符串数组</returns>
public static string[] GetCityWeather(string cityCode)
{
string cacheName = "Weather" + cityCode.Trim();
string[] WeatherArray=(string[])HttpContext.Current.Cache[cacheName];
if (WeatherArray == null)
{
cn.com.webxml.www.WeatherWebService weather = new MyWeather.cn.com.webxml.www.WeatherWebService();
WeatherArray = weather.getWeatherbyCityName(cityCode.Trim());
HttpContext.Current.Cache.Insert(cacheName, WeatherArray, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
}
return WeatherArray;
}
}
}

啊啊
  • 打赏
  • 举报
回复
楼主要吗给邮箱我传你
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeather
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
DataSet mds = WeatherClass.getSupportDataSet();
if (!Page.IsPostBack)
{
DataTable dt = mds.Tables[0];//支持的省洲
this.Province.DataSource = dt;
this.Province.DataValueField = "ID";//Value存储省洲代码
this.Province.DataTextField = "Zone";//显示省洲名称
this.Province.DataBind();
City.SelectedIndex = 1;
CityDataBind("1");//默认直辖市
GetWeatherByCode("54511");// 默认北京
}
}
catch (Exception)
{
Title.Text = "发现一个错误";
}
}
/// <summary>
/// 根据城市代码取得该城市的天气,并绑定到相关的显示控件
/// </summary>
/// <param name="cityCode">城市代码</param>
protected void GetWeatherByCode(string cityCode)
{
String[] wa = WeatherClass.GetCityWeather(cityCode.Trim());//天气的字符串数组
Label1.Text = wa[10];
Label2.Text = wa[6] + "   " + wa[5] + "   " + wa[7];
Label3.Text = wa[13] + "   " + wa[12] + "   " + wa[14];
Label4.Text = wa[18] + "   " + wa[17] + "   " + wa[19];
Label5.Text = wa[11].Replace("\n", "<br />");
Label6.Text = wa[22].Replace("\n", "<br />");
Label7.Text = DateTime.Parse(wa[4]).ToString("yyyy年MM月dd日 dddd HH:mm");
Label8.Text = wa[0] + " / " + wa[1];
Image1.ImageUrl = "~/images/weather/" + wa[8];
Image2.ImageUrl = "~/images/weather/" + wa[9];
Image3.ImageUrl = "~/images/weather/" + wa[15];
Image4.ImageUrl = "~/images/weather/" + wa[16];
Image5.ImageUrl = "~/images/weather/" + wa[20];
Image6.ImageUrl = "~/images/weather/" + wa[21];
CityPhoto.ImageUrl = "http://www.cma.gov.cn/tqyb/img/city/" + wa[3];
CityPhoto.AlternateText = City.SelectedItem.Text;
}
/// <summary>
/// 绑定城市的数据,根据省洲代码对显示进行筛选
/// </summary>
/// <param name="zoneID">省洲代码</param>
protected void CityDataBind(string zoneID)
{
DataView dv = new DataView(WeatherClass.getSupportDataSet().Tables[1]);
dv.RowFilter = "[ZoneID] = " + zoneID;//筛选的条件是ZoneID=省洲代码
City.DataSource = dv;
City.DataTextField = "Area";
City.DataValueField = "AreaCode";
City.DataBind();
City.Items.Insert(0, new ListItem("选择城市", "0"));
City.SelectedIndex = 0;
}
/// <summary>
/// 省洲选择变化的事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Province_SelectedIndexChanged(object sender, EventArgs e)
{
CityDataBind(Province.SelectedItem.Value.Trim());
}
/// <summary>
/// 城市选择变化的事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void City_SelectedIndexChanged(object sender, EventArgs e)
{
if (City.Items[0].Value == "0")
{
City.Items.RemoveAt(0);
}
GetWeatherByCode(City.SelectedItem.Value.Trim());
}
}
}

哈哈
jss122414092 2011-10-18
  • 打赏
  • 举报
回复
在回答5楼的,放到页面就自动调用了,同志,,
jss122414092 2011-10-18
  • 打赏
  • 举报
回复
放到页面就ok了,这个是天气网站提供的接口,,谢谢,楼主,不信可以试
fangyuantdy 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jss122414092 的回复:]
C# code



<iframe src="http://www.zzsky.cn/code/weather/weather1.htm"

width="170" height="15" marginwidth="0" marginheight="0" hspace="0"

vspace="0" frameborder="0" scrolling="no"></iframe>


放……
[/Quote]
这个是接口?接口这么调用的?忽悠谁啊
jss122414092 2011-10-18
  • 打赏
  • 举报
回复




<iframe src="http://www.zzsky.cn/code/weather/weather1.htm"

width="170" height="15" marginwidth="0" marginheight="0" hspace="0"

vspace="0" frameborder="0" scrolling="no"></iframe>

放到页面调用就可以了,这个就是接口,,谢谢,给分,
yzf86211861 2011-10-18
  • 打赏
  • 举报
回复
网页抓取
cf_nxcxy 2011-10-18
  • 打赏
  • 举报
回复
fangyuantdy 2011-10-18
  • 打赏
  • 举报
回复
调用雅虎或者其他开放的WebService
fanxin_1999 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jss122414092 的回复:]
C# code
<iframe src="http://www.zzsky.cn/code/weather/weather1.htm"

width="170" height="15" marginwidth="0" marginheight="0" hspace="0"

vspace="0" frameborder="0" scrolling="no"></ifr……
[/Quote]

测试了一下,4楼提供的代码可以用。
x363961461 2011-10-18
  • 打赏
  • 举报
回复
楼上都可以。
关键代码就2行。。。。。。。。。。。
其它只是怎么显示格式而已
liguokun 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 hhqsy 的回复:]
楼主要吗给邮箱我传你
[/Quote]

好的啊:34341369@qq.com,谢谢了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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