📄 weather.ashx
字号:
<%@ WebHandler Language="C#" Class="weather" %>
using System;
using System.Web;
using System.Text.RegularExpressions;
using System.Text;
//获得天气预报的handler
public class weather : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";//返回的文本类型
string post = Tools.getpost();//获得post的数据
string xmlstr = Thief.Get("http://weather.tq121.com.cn/detail.php?" + post);//取得远程页面的内容
//用于匹配的正则表达式
string temp = "<table width=\"790\" height=\"2101\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#94CEEF\">[\\s\\S]*?(?=<table width=\"790\" height=\"100\" border=\"0\" align=\"center\")";
xmlstr = Regex.Match(xmlstr, temp, RegexOptions.IgnoreCase).Value;
xmlstr = Tools.delTag(xmlstr, "a", true);//删除超连接
//图片改为绝对路径
xmlstr = Regex.Replace(xmlstr, "(?<=\")(images/)", "http://weather.tq121.com.cn/$1", RegexOptions.IgnoreCase);
xmlstr = Regex.Replace(xmlstr, "\\.\\./(images)", "http://weather.tq121.com.cn/$1", RegexOptions.IgnoreCase);
xmlstr = Tools.delTag(xmlstr, "input", false);//删除input标记
context.Response.Write(xmlstr);//输出
}
public bool IsReusable//不重用
{
get
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -