天气预报[取自sohu]
2006年05月26日 1:09 下午 | 分类:Develop
本打算”偷”Yahoo的,但后来还是爱上sohu的了
立马就放了上来
大家可以看看效果
面朝大海,春暖花开
本打算”偷”Yahoo的,但后来还是爱上sohu的了
立马就放了上来
大家可以看看效果
下午弄出来的
准备用到blog上
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
public partial class Default2 : System.Web.UI.Page
{
protected string _content;
protected void Page_Load(object sender, EventArgs e)
{
GetWebInfo web = new GetWebInfo(new UriBuilder(@"http://weather.cn.yahoo.com/area.html?city=%CE%E4%BA%BA"));
_content = web.LinkFind();
}
}
class GetWebInfo
{
public String filetext;
public GetWebInfo(UriBuilder url)
{
filetext = "";
HttpWebRequest rs = (HttpWebRequest)WebRequest.Create(url.Uri);
try
{
HttpWebResponse rsp = (HttpWebResponse)rs.GetResponse();
using (StreamReader reader = new StreamReader(rsp.GetResponseStream(), System.Text.Encoding.Default))
{
String tmstr = "";
while ((tmstr = reader.ReadLine()) != null)
{
filetext += tmstr;
}
}
}
catch
{
}
}
public string LinkFind()
{
Regex r;
Match m;
string _str = "";
r = new Regex("<!--3-->\\s*(?<1>.*[^<])<!--3-->",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
for (m = r.Match(filetext); m.Success; m = m.NextMatch())
{
_str+=m.Groups[1].ToString();
}
return _str;
}
}
重写了Stream类
本站就是这样实现的
需要引入Microsoft.VisualBasic;
class CnToTwStream : Stream
{
private Stream _sink;
private MemoryStream _ms;
private Encoding _encoding;</code>
public CnToTwStream(Stream sink, Encoding encoding)
{
_sink = sink;
_ms = new MemoryStream();
_encoding = encoding;
}
public override bool CanRead
{
get { return false; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override long Length
{
get { return _ms.Length; }
}
public override long Position
{
get { return _ms.Position; }
set { throw new NotSupportedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
public override long Seek(long offset, System.IO.SeekOrigin direction)
{
throw new NotSupportedException();
}
public override void SetLength(long length)
{
throw new NotSupportedException();
}
public override void Close()
{
_ms.Close();
byte[] buffer_cn = _ms.GetBuffer();
string str_cn = _encoding.GetString(buffer_cn);
string str_tw = Strings.StrConv(str_cn, VbStrConv.TraditionalChinese, 0);
byte[] buffer_tw = _encoding.GetBytes(str_tw);
using (_sink)
{
_sink.Write(buffer_tw, 0, buffer_tw.Length);
}
}
public override void Flush()
{
_ms.Flush();
}
public override void Write(byte[] buffer, int offset, int count)
{
_ms.Write(buffer, offset, count);
}
}