weather.ashx

来自「我写的一个小偷模块 非常实用 内有详细说明」· ASHX 代码 · 共 31 行

ASHX
31
字号
<%@ 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 + =
减小字号Ctrl + -
显示快捷键?