无为清净楼资源网 Design By www.qnjia.com
本文详细介绍关于ASP.NET的实时天气及24小时天气预报
修改其中的url获得其他城市的天气情况的文章专题。
ASP.NET的实时天气及24小时天气预报(C#)
修改其中的url获得其他城市的天气情况
如广州为:
http://weather.yahoo.com
/forecast/CHXX0037_c.html
注意仅适用于获得yahoo上的天气预报
GetWeather.aspx
-----------------------------------
复制代码 代码如下:<%@ Page language="c#" Codebehind="GetWeather.aspx.cs" AutoEventWireup="false" Inherits="test.GetWeather" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>GetWeather</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="GetWeather" method="post" runat="server">
<FONT face="宋体">
<P>
<asp:Label id="lblWeather" runat="server">Weather</asp:Label></P>
<P>
<asp:Button id="btnGet" runat="server" Text="Get Weather">
</asp:Button></P>
<P>
<asp:Label id="Weather2" runat="server">24小时天气</asp:Label></P>
<P>
<asp:Button id="btnGet2" runat="server" Text="天气预报">
</asp:Button></P>
</FONT>
</form>
</body>
</HTML>
getWeather.aspx.cs
---------------------------------------
复制代码 代码如下:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
namespace test
{
public class GetWeather : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblWeather;
protected System.Web.UI.WebControls.Label Weather2;
protected System.Web.UI.WebControls.Button btnGet2;
protected System.Web.UI.WebControls.Button btnGet;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnGet.Click += new System.EventHandler(this.btnGet_Click);
this.btnGet2.Click += new System.EventHandler(this.btnGet2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnGet_Click(object sender, System.EventArgs e)
{
WebRequest wreq=WebRequest.Create
("http://weather.yahoo.com/forecast/CHXX0037_c.html");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
string HTML ="";
Stream s=wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s);
string sLine = "";
int i = 0;
while (sLine!=null)
{
i++;
sLine = objReader.ReadLine();
if (sLine!=null)
HTML += sLine;
}
String temp= "";
int start,stop;
start = HTML.IndexOf("<!-- CURCON-->",0,HTML.Length);
stop = HTML.IndexOf("<!-- END CURCON-->",0,HTML.Length);
temp = HTML.Substring(start, stop - start);
start = temp.IndexOf("<b>");
stop = temp.IndexOf("</b>");
string degree = temp.Substring(start+3,stop - start -3);
start = temp.IndexOf("<img");
stop = temp.IndexOf("</td>",start);
string img = temp.Substring(start,stop - start);
lblWeather.Text = degree + "<br>" + img;
}
private void btnGet2_Click(object sender, System.EventArgs e)
{
WebRequest wreq=WebRequest.Create
("http://cn.weather.yahoo.com/CHXX/CHXX0037/index_c.html");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
string HTML ="";
Stream s=wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
string sLine = "";
int i = 0;
while (sLine!=null)
{
i++;
sLine = objReader.ReadLine();
if (sLine!=null)
HTML += sLine;
}
String temp= "";
int start,stop;
start = HTML.IndexOf("<table border=0 cellpadding=2
cellspacing=1 bgcolor=9999cc width=\"85%\">",0,HTML.Length);
stop = HTML.IndexOf("</table>",start)+8;
temp = HTML.Substring(start, stop - start);
Weather2.Text = temp;
}
}
} 请注明转自chinazhan中国站长
修改其中的url获得其他城市的天气情况的文章专题。
ASP.NET的实时天气及24小时天气预报(C#)
修改其中的url获得其他城市的天气情况
如广州为:
http://weather.yahoo.com
/forecast/CHXX0037_c.html
注意仅适用于获得yahoo上的天气预报
GetWeather.aspx
-----------------------------------
复制代码 代码如下:<%@ Page language="c#" Codebehind="GetWeather.aspx.cs" AutoEventWireup="false" Inherits="test.GetWeather" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>GetWeather</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="GetWeather" method="post" runat="server">
<FONT face="宋体">
<P>
<asp:Label id="lblWeather" runat="server">Weather</asp:Label></P>
<P>
<asp:Button id="btnGet" runat="server" Text="Get Weather">
</asp:Button></P>
<P>
<asp:Label id="Weather2" runat="server">24小时天气</asp:Label></P>
<P>
<asp:Button id="btnGet2" runat="server" Text="天气预报">
</asp:Button></P>
</FONT>
</form>
</body>
</HTML>
getWeather.aspx.cs
---------------------------------------
复制代码 代码如下:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
namespace test
{
public class GetWeather : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblWeather;
protected System.Web.UI.WebControls.Label Weather2;
protected System.Web.UI.WebControls.Button btnGet2;
protected System.Web.UI.WebControls.Button btnGet;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnGet.Click += new System.EventHandler(this.btnGet_Click);
this.btnGet2.Click += new System.EventHandler(this.btnGet2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnGet_Click(object sender, System.EventArgs e)
{
WebRequest wreq=WebRequest.Create
("http://weather.yahoo.com/forecast/CHXX0037_c.html");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
string HTML ="";
Stream s=wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s);
string sLine = "";
int i = 0;
while (sLine!=null)
{
i++;
sLine = objReader.ReadLine();
if (sLine!=null)
HTML += sLine;
}
String temp= "";
int start,stop;
start = HTML.IndexOf("<!-- CURCON-->",0,HTML.Length);
stop = HTML.IndexOf("<!-- END CURCON-->",0,HTML.Length);
temp = HTML.Substring(start, stop - start);
start = temp.IndexOf("<b>");
stop = temp.IndexOf("</b>");
string degree = temp.Substring(start+3,stop - start -3);
start = temp.IndexOf("<img");
stop = temp.IndexOf("</td>",start);
string img = temp.Substring(start,stop - start);
lblWeather.Text = degree + "<br>" + img;
}
private void btnGet2_Click(object sender, System.EventArgs e)
{
WebRequest wreq=WebRequest.Create
("http://cn.weather.yahoo.com/CHXX/CHXX0037/index_c.html");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
string HTML ="";
Stream s=wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
string sLine = "";
int i = 0;
while (sLine!=null)
{
i++;
sLine = objReader.ReadLine();
if (sLine!=null)
HTML += sLine;
}
String temp= "";
int start,stop;
start = HTML.IndexOf("<table border=0 cellpadding=2
cellspacing=1 bgcolor=9999cc width=\"85%\">",0,HTML.Length);
stop = HTML.IndexOf("</table>",start)+8;
temp = HTML.Substring(start, stop - start);
Weather2.Text = temp;
}
}
} 请注明转自chinazhan中国站长
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月20日
2024年11月20日
- 群星《一人一首成名曲》1998 台湾金碟珍藏版[WAV+CUE][1.1G]
- 陈百强2024-《凝望》头版限量编号MQA-UHQCD[WAV+CUE]
- 测试示范《监听天碟3》头版限量编号LECD[WAV+CUE]
- 陈瑞《爱你到天荒地老HQ》头版限量[低速原抓WAV+CUE]
- 徐小凤 《徐小凤殿堂18首》24K金碟[WAV+CUE]
- 保时捷原厂车载爆棚动态试音碟《Panamera_Soundtrack》DTS[WAV分轨][1G]
- 容祖儿《小小》香港首版 [WAV+CUE][1.1G]
- 莫文蔚《拉活…》SONY [WAV+CUE][1G]
- Beyond《极品天碟》LPCD45II首批限量版[WAV+CUE][1.7G]
- HIFI示范巅峰之作《情解药·Hi-Fi心魂》2CD[WAV+CUE]
- 房东的猫2021-关于彻夜不眠的事情(EP)[青柴文化][WAV+CUE]
- 群星.1993-一曲成名·青春无悔【飞碟】【WAV+CUE】
- 张芸京.2016-失败的高歌【泡耳音乐】【WAV+CUE】
- 天籁女声《2024第31届上海国际高端音影展纪念CD》[WAV+CUE][1.1G]
- 姚斯婷 《敢爱敢做》头版限量编号24K金碟[低速原抓WAV+CUE][1.2G]