⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rule_manage.aspx.cs

📁 资源大小: 116.59KB 资源类型: application 自己写个采集器 采集起来更灵活
💻 CS
📖 第 1 页 / 共 3 页
字号:
            {
                if (Button1.Text == "增加规则")
                {
                    try
                    {

                        string url = "";
                        if (this.CheckBox1.Checked)
                        {
                            url = this.TextBox2.Text.Trim() + " " + this.TextBox3.Text.Trim() + " " + this.TextBox4.Text.Trim();
                        }
                        else
                        {
                            url = this.TextBox2.Text.Trim();
                        }
                        string sql = string.Format("insert into collection_rule (rule_name,list_url,rule_0,rule_1,rule_2,rule_3,rule_4,rule_5,rule_num,rule_bianma,rule_6,rule_7) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", this.TextBox1.Text.Trim(), url, this.TextBox6.Text.Trim(), this.TextBox7.Text.Trim(), this.TextBox8.Text.Trim()+"&&&&"+this.RadioButtonList2.SelectedItem.Value.Trim(), this.TextBox9.Text.Trim(), this.TextBox10.Text.Trim(), this.TextBox11.Text.Trim()+"&&&&"+this.RadioButtonList1.SelectedItem.Value.Trim(), this.ListBox1.Items.Count, this.TextBox5.Text.Trim(),this.TextBox16.Text.Trim(),this.TextBox17.Text.Trim());
                        SqlDataSource1.InsertCommand = sql;
                        int i = SqlDataSource1.Insert();
                        if (i == 1)
                        {
                            Response.Write("<script>alert('规则增加成功')</script>");
                            this.TextBox1.Text = "";
                            this.TextBox2.Text = "";
                            this.TextBox3.Visible = false;
                            this.TextBox4.Visible = false;
                            this.Label1.Visible = false;
                            this.CheckBox1.Checked = false;
                            this.TextBox5.Text = "";
                            this.TextBox6.Text = "";
                            this.TextBox7.Text = "";
                            this.TextBox8.Text = "";
                            this.TextBox9.Text = "";
                            this.TextBox10.Text = "";
                            this.TextBox11.Text = "";
                            this.TextBox12.Text = "";
                            //this.TextBox13.Text = "";
                            //this.TextBox14.Text = "";
                            this.TextBox15.Text = "";
                            this.ListBox1.Items.Clear();
                        }
                        else
                        {
                            Response.Write("<script>alert('规则增加失败')</script>");
                        }
                    }
                    catch
                    {
                        Response.Write("<script>alert('规则增加失败')</script>");
                    }
                }

                if (Button1.Text == "修改规则")
                {
                    try
                    {
                        string url = "";
                        if (this.CheckBox1.Checked)
                        {
                            url = this.TextBox2.Text.Trim() + " " + this.TextBox3.Text.Trim() + " " + this.TextBox4.Text.Trim();
                        }
                        else
                        {
                            url = this.TextBox2.Text.Trim();
                        }
                        if (this.ListBox1.Items[0].Text == "请先测试采集")
                        {
                            Response.Write("<script>alert('请先测试采集')</script>");


                        }
                        else
                        {
                            string sql = string.Format("update collection_rule set list_url='{0}',rule_0='{1}',rule_1='{2}',rule_2='{3}',rule_3='{4}',rule_4='{5}',rule_5='{6}',rule_num='{7}',rule_bianma='{8}',rule_6='{9}',rule_7='{10}' where rule_name='{11}'", url, this.TextBox6.Text.Trim(), this.TextBox7.Text.Trim(), this.TextBox8.Text.Trim()+"&&&&"+RadioButtonList2.SelectedItem.Value.Trim(), this.TextBox9.Text.Trim(), this.TextBox10.Text.Trim(), this.TextBox11.Text.Trim() + "&&&&" + this.RadioButtonList1.SelectedItem.Value.Trim(), this.ListBox1.Items.Count, this.TextBox5.Text.Trim(), this.TextBox16.Text.Trim(), this.TextBox17.Text.Trim(), this.TextBox1.Text.Trim());
                            SqlDataSource1.UpdateCommand = sql;
                            int i = SqlDataSource1.Update();
                            if (i == 1)
                            {
                                Response.Write("<script>alert('规则修改成功')</script>");

                            }
                            else
                            {
                                Response.Write("<script>alert('规则修改失败')</script>");
                            }
                        }
                    }
                    catch
                    {
                        Response.Write("<script>alert('规则修改失败')</script>");
                    }
                    this.Label6.Text = "新规则";
                    this.Button1.Text = "增加规则";
                    this.TextBox1.Text = "";
                    this.TextBox2.Text = "";
                    this.TextBox3.Visible = false;
                    this.TextBox4.Visible = false;
                    this.Label1.Visible = false;
                    this.CheckBox1.Checked = false;
                    this.TextBox5.Text = "";
                    this.TextBox6.Text = "";
                    this.TextBox7.Text = "";
                    this.TextBox8.Text = "";
                    this.TextBox9.Text = "";
                    this.TextBox10.Text = "";
                    this.TextBox11.Text = "";
                    this.TextBox12.Text = "";
                    //this.TextBox13.Text = "";
                    //this.TextBox14.Text = "";
                    this.TextBox15.Text = "";
                    this.ListBox1.Items.Clear();
                }

            }
        }
        else
        {
            Response.Redirect("jiaoyou.aspx");
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            for (int i = 0; i < RadioButtonList1.Items.Count; i++)
            {
                RadioButtonList1.Items[i].Selected = false;
            }
            for (int i = 0; i < RadioButtonList2.Items.Count; i++)
            {
                RadioButtonList2.Items[i].Selected = false;
            }
            if (e.CommandName == "sel")
            {
                this.Label6.Text = "修改规则";
                this.Button1.Text = "修改规则";
                this.TextBox1.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label1"))).Text;
                string[] url = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label3"))).Text.Trim().Split(' ');
                if (url.Length > 1)
                {
                    this.CheckBox1.Checked = true;
                    this.Label1.Visible = true;
                    this.TextBox3.Visible = true;
                    this.TextBox4.Visible = true;
                    this.TextBox3.Text = url[1];
                    this.TextBox4.Text = url[2];
                }
                else
                {
                    this.CheckBox1.Checked = false;
                    this.Label1.Visible = false;
                    this.TextBox3.Visible = false;
                    this.TextBox4.Visible = false;
                }
                this.TextBox2.Text = url[0];
                this.TextBox5.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label2"))).Text;
                this.TextBox6.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label4"))).Text;
                this.TextBox7.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label5"))).Text;

                string[] nummmm = split(((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label6"))).Text.Trim(), "&&&&");
                this.TextBox8.Text = nummmm[0];
                for (int i = 0; i < RadioButtonList2.Items.Count; i++)
                {
                    if (nummmm[1] == RadioButtonList2.Items[i].Value)
                    {
                        RadioButtonList2.Items[i].Selected = true;
                    }
                }
                this.TextBox9.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label7"))).Text;
                this.TextBox10.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label8"))).Text;
                string[] numm = split(((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label9"))).Text.Trim(), "&&&&");
                this.TextBox11.Text = numm[0];
                for (int i = 0; i < RadioButtonList1.Items.Count; i++)
                {
                    if (numm[1] == RadioButtonList1.Items[i].Value)
                    {
                        RadioButtonList1.Items[i].Selected = true;
                    }
                }
                this.TextBox16.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label10"))).Text;
                this.TextBox17.Text = ((Label)(this.GridView1.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label11"))).Text;
            }
        }
        catch
        { }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.TextBox15.Text = get();
    }

    public string get()
    {
        try
        {
            string a = "";

            int m = 1;

            string[] wenzhang = split(this.TextBox11.Text.Trim(),"||||");

            string usedataHTML = this.TextBox12.Text.Trim();

            if (this.TextBox12.Text.Trim() == "")
            {
                Response.Write("<script>alert('请先测试文章内容')</script>");
            }
            else
            {
                for (int i = 0; i < wenzhang.Length; i++)
                {
                    
                    string b = "";
                    
                    if (RadioButtonList1.Items[0].Selected == true)
                    {
                        regexzj = new Regex(wenzhang[i].Trim(), RegexOptions.IgnoreCase);
                    }
                    if (RadioButtonList1.Items[1].Selected == true)
                    {
                        regexzj = new Regex(wenzhang[i].Trim(), RegexOptions.Singleline);
                    }
                    if (RadioButtonList1.Items[2].Selected == true)
                    {
                        regexzj = new Regex(wenzhang[i].Trim(), RegexOptions.ExplicitCapture);
                    }
                    if (RadioButtonList1.Items[3].Selected == true)
                    {
                        regexzj = new Regex(wenzhang[i].Trim(), RegexOptions.Multiline);
                    }
                    MatchCollection matches = regexzj.Matches(this.TextBox12.Text.Trim());
                    System.Collections.IEnumerator enu = matches.GetEnumerator();
                    while (enu.MoveNext() && enu.Current != null)
                    {
                        Match match = (Match)(enu.Current);
                        b += match.Value;
                    }
                    a += "@"+(i+1)+b;

                    m++;
                }
            }
            return a+"@"+m;

        }
        catch
        { 
        }
        return "";
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        try
        {
            string end = this.TextBox15.Text.Trim();
            if (this.TextBox16.Text.Trim() != "")
            {
                string[] tihuan1 = split(this.TextBox16.Text.Trim(), "||||");
                string[] tihuan2 = split(this.TextBox17.Text, "||||");
                for (int i = 0; i < tihuan1.Length; i++)
                {
                    if (this.TextBox16.Text != "")
                    {
                        if (this.TextBox17.Text.Trim() != "")
                        {
                            if (tihuan1.Length == tihuan2.Length)
                            {
                                Regex myreg = new Regex(tihuan1[i], RegexOptions.Singleline);
                                this.TextBox15.Text = myreg.Replace(this.TextBox15.Text.Trim(), tihuan2[i]);
                            }
                            else
                            {
                                Regex myreg = new Regex(tihuan1[i], RegexOptions.Singleline);
                                this.TextBox15.Text = myreg.Replace(this.TextBox15.Text.Trim(), tihuan2[0]);
                            }
                        }
                        else
                        {
                            Regex myreg = new Regex(tihuan1[i], RegexOptions.Singleline);
                            this.TextBox15.Text = myreg.Replace(this.TextBox15.Text.Trim(),"");
                        }
                    }
                }
            }
        }
        catch
        { }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -