ASP.NET的實(shí)時(shí)天氣及24小時(shí)天氣預(yù)報(bào)_.Net教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:在ASP.NET中進(jìn)行文件處理(1)一種程序設(shè)計(jì)語(yǔ)言,對(duì)文件處理的能力的大小往往也是一種語(yǔ)言功能大小的一種表現(xiàn)。在ASP.NET中,對(duì)于文件的處理主要是通過(guò).Net FrameWork SDK中的一個(gè)System.IO的名稱空間來(lái)實(shí)現(xiàn)了,在System.IO
修改其中的url獲得其他城市的天氣情況
如廣州為:
http://weather.yahoo.com/forecast/CHXX0037_c.html
注意僅適用于獲得yahoo上的天氣預(yù)報(bào)
以下為引用的內(nèi)容: 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小時(shí)天氣</asp:Label></P> <P> <asp:Button id="btnGet2" runat="server" Text="天氣預(yù)報(bào)"></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; } } } |
分享:帶你走進(jìn)ASP.NET(2)C#語(yǔ)言是微軟公司針對(duì).Net平臺(tái)開(kāi)發(fā)的一種全新的編程語(yǔ)言。盡管C#象是C,和C 語(yǔ)言的升級(jí)語(yǔ)言,但是他不象他的前身那樣,C#是一個(gè)完全面相對(duì)象的開(kāi)發(fā)語(yǔ)言。它既有Visual Basic的快速開(kāi)發(fā)的特點(diǎn),
相關(guān).Net教程:
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見(jiàn)代碼存在的偽造IP問(wèn)題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- Google免費(fèi)的SVN服務(wù)器管理VS2010代碼
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- asp.net 編輯gridview的小例子
- 將非模態(tài)對(duì)話框顯示為模態(tài)對(duì)話框
- ASP.NET 2.0發(fā)送電子郵件中存在的問(wèn)題
- 解讀多語(yǔ)言開(kāi)發(fā)的個(gè)人體驗(yàn)
- “黑盒測(cè)試管理”以外的編程經(jīng)驗(yàn)片斷
- 淺析C# 2010命名和可選參數(shù)的新特性
- 一個(gè)無(wú)刷新效果定時(shí)自動(dòng)更新頁(yè)面的例子
- 怎樣使ASP.NET從字符串中查找字符出現(xiàn)的次數(shù)
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索ASP.NET的實(shí)時(shí)天氣及24小時(shí)天氣預(yù)報(bào)
- 教程說(shuō)明:
.Net教程-ASP.NET的實(shí)時(shí)天氣及24小時(shí)天氣預(yù)報(bào)。