- 热门文章:
- · 使用C#代码实现增加用户帐号
- · 用c#写的smtp邮件发送类
- · C# Builder 实现POP3信箱的监视
- · 一个有KeepConnection开关的C#的Database类
- · 一个用C#写的词法分析程序
- · 利用自定义事件实现不同窗体间的通讯 -- C#篇
- · 用C#开发.NET CF 蓝牙通信模块
- · 关于C#下写的Web Service 服务在Delphi下调用时的问题
- · 用C#写的一个简单屏幕保护程序
- · .Net/C#: 利用反射编写通用的 rss 2.0 的 reader
- · C# Programming guidlines
- · QQ验证码识别源代码(C#/NET1.1)
上一篇:用托盘控制windows服务的c#实现 >>
ASP.NET的实时天气及24小时天气预报(C#)
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="java script">
<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;
}
}
}
下一篇:使用C#代码实现增加用户帐号 >>
相关文章:
- · C#教学经验谈(3):储蓄计算器的源程序
- · C#实现Window管道技术
- · C#教学经验谈(2):会跑的按钮
- · c#取得汉字的拼音的首字母
- · C#做的一个加密/解密的类
- · c#发送需要smtp认证的邮件
- · c#中ref和out参数使用时需要注意的问题
- · 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
- · C#代码
- · 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分
- · c#.net常用的小函数和方法集
- · RC2加密算法在C#的应用----完善版
- · 简单的c#文本文件读写
- · c#.net常用的小函数和方法集
- · 用Visual C#打造个性化的IE浏览器
- · 如何用UltraEdit编译C#源程序
- · .Net/C#: 实现支持断点续传多线程下载的 Http Web 客户端工具类 (C# DIY HttpWebClient)
- · Visual C#网络编程之TCP
- · C# Programming Guidelines
- · C#设计模式之原型(ProtoType)
- · C#设计模式之抽象工厂(AbstractFactory)
- · C# Coding Standard
- · c#.net常用的小函数和方法集
- · c#.net函数列表.txt
- · c#.net常用的小函数参考
- · C#中使用XML——编写XML
- · C#版ftp方法实现类库代码
- · Visual C# .NET 入门
- · 在C#后代码里使用IE WEB Control TreeView
- · C#里操作时间的例子!
- · 在C#中利用SharpZipLib进行文件的压缩和解压缩
- · C#中使用XML——基于DOM的案例分析
- · 远程重启计算机(C#)
- · C#中使用XML——实现DOM
- · C#中使用XML——编写XML
- · 用C#实现生成PDF文档
- · 使用C#编写的一个定时关机程序
- · 三层架构之数据库访问层完全篇(C#)
