<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

     

    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.Text.RegularExpressions;
    using System.Collections;
    using System.IO;
    using System.Net;
    using System.Text;
    namespace NewsCollection
    {
        public partial class SiteEdit : System.Web.UI.Page
        {
            string urlData = "";
            protected void Page_Load(object sender, EventArgs e)
            {
                this.BtCollection.Attributes.Add("onclick", "Status.showInfo('加載中');");
                if (!Page.IsPostBack)
                {
                    AjaxAction();
                    BindData();
                }
            
            }
            public string GetRequest(string key)
            {
                key = Convert.ToString(Request[key]??"");
                key = key==null?(""):(key);
                return key;
            }
            public void AjaxAction()
            {
                string isAjax = GetRequest("isAjax").ToLower();
                if (isAjax == "true")
                {
                    string state = "";
                    string action = this.GetRequest("action").ToLower();
                    string values = this.GetRequest("values");
                    if (action == "newsbody")
                    {
                        string modelstart = this.GetRequest("modelstart");
                        string modelend = this.GetRequest("modelend");
                        string modelbody = this.GetRequest("modelbody");
                        string siteUrl = this.GetRequest("siteUrl");
                        ArrayList al = this.GetModelData(modelstart, modelend, modelbody, siteUrl);
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in al)
                        {
                            sb.Append(s);
                        }
                        state = sb.ToString();
                    }
                    else if (action == "newsdetail")
                    {
                        string modelstart = this.GetRequest("modelstart");
                        string modelend = this.GetRequest("modelend");
                        string modelbody = this.GetRequest("modelbody");
                        string siteUrl = this.GetRequest("siteUrl");
                        string newsTitleStart = this.GetRequest("newsTitleStart");
                        string newsTitleEnd = this.GetRequest("newsTitleEnd");
                        string newsContentStart = this.GetRequest("newsContentStart");
                        string newsContentEnd = this.GetRequest("newsContentEnd");
                        state = GetNews(GetModelData(modelstart, modelend, modelbody, siteUrl), newsTitleStart, newsTitleEnd, newsContentStart, newsContentEnd);
                    }
                    else
                    {
                        state = "test Ajax";
                    }
                    Response.Clear();
                    Response.Write(state);
                    Response.End();
                }
            }
            public void BindData()
            {
                string Gid = Convert.ToString(Request["Gid"] ?? "");
                if (Gid.Length > 0)
                {
                    Beans.Sites sites = new Beans.Sites();
                    sites.Gid = Gid;
                    sites = sites.SelectById();
                    TbSiteName.Text  = sites.SiteName;
                    TbSiteUrl.Text =sites.SiteUrl;
                    TbSiteModelStart.Text = sites.SiteModelStart;
                    TbSiteModelEnd.Text =sites.SiteModelEnd;
                    TbSiteModelBody.Text = sites.SiteModelBody;
                    TbNewsTitleStart.Text =sites.NewsTitleStart;
                    TbNewsTitleEnd.Text =sites.NewsTitleEnd;
                    TbNewsContentStart.Text =sites.NewsContentStart;
                    TbNewsContentEnd.Text =sites.NewsContentEnd;
                }
            }
            protected void BtEdit_Click(object sender, EventArgs e)
            {
                string message = "系統錯誤請重試";
                string script = "history.go(-1)";
                string Gid = Convert.ToString(Request["Gid"]??"");
                Beans.Sites sites = new Beans.Sites();
                sites.SiteName = TbSiteName.Text.Trim();
                sites.SiteUrl = TbSiteUrl.Text.Trim();
                sites.SiteModelStart = TbSiteModelStart.Text.Trim();
                sites.SiteModelEnd = TbSiteModelEnd.Text.Trim();
                sites.SiteModelBody = TbSiteModelBody.Text.Trim();
                sites.NewsTitleStart = TbNewsTitleStart.Text.Trim();
                sites.NewsTitleEnd = TbNewsTitleEnd.Text.Trim();
                sites.NewsContentStart = TbNewsContentStart.Text.Trim();
                sites.NewsContentEnd = TbNewsContentEnd.Text.Trim();
                if (Gid.Length > 0)
                {
                    sites.Gid=Gid;
                    if (sites.Update())
                    {
                        message = "修改成功!";
                    }
                 
                }
                else
                {
                    if (sites.Add())
                    {
                        message = "添加成功!";
                    }
                  
                }
                Response.Write("<script type='text/javascript'>alert('"+message+"');"+script+"</script>");
             
            }

            protected void BtCollection_Click(object sender, EventArgs e)
            {
                GetNews(GetModelData(TbSiteModelStart.Text.Replace("(", "\\(").Replace(")", "\\)").Replace(".", "\\."), TbSiteModelEnd.Text.Replace("(", "\\(").Replace(")", "\\)").Replace(".", "\\."), TbSiteModelBody.Text, TbSiteUrl.Text), TbNewsTitleStart.Text.Trim(), TbNewsTitleEnd.Text.Trim(), TbNewsContentStart.Text.Trim(), TbNewsContentEnd.Text.Trim());
         
               // GetNews(GetModelData(TbSiteModelStart.Text.Replace("(", "\\(").Replace(")", "\\)").Replace(".", "\\."), TbSiteModelEnd.Text.Replace("(", "\\(").Replace(")", "\\)").Replace(".", "\\."), TbSiteModelBody.Text, TbSiteUrl.Text));
            }
            public ArrayList GetModelData(string modelstart,string modelend,string modelbody,string SiteUrl)
            {

                ArrayList al = new ArrayList();
                string content = GetHttpData(SiteUrl,"gb2312");
                Regex reg = new Regex(modelstart+"(?<newsBody>[\\s\\S]*)"+modelend, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                Match mat = reg.Match(content);
                //TbContent.Text = mat.Groups["newsBody"].Value.ToString();
                Regex regurl = new Regex(modelbody.Replace("_url_", "(?<url>[^\"'\\s]+)"), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                Match maturl = regurl.Match(mat.Groups["newsBody"].Value.ToString());
                while (maturl.Success)
                {
                    //z-zA-A0-9/\\.:
                    string temp = maturl.Groups["url"].Value;
                    al.Add(temp);
                    Response.Write(temp.StartsWith("http://") ? (temp) : (temp.Insert(0, "http://" + SiteUrl.Replace("http://","").Substring(0, SiteUrl.LastIndexOf("/")))) + "<br>");
                    maturl = maturl.NextMatch();
                }
                return  al;
            }
        
            public string  GetNews(ArrayList al,string titleStart,string titleEnd,string contentStart,string contetnEnd)
            {
                StringBuilder sb = new StringBuilder();
                if (al != null)
                {
                
                    foreach (string s in al)
                    {

                        Regex reg = new Regex(titleStart.Replace("(", "\\(").Replace(")", "\\)") + "(?<title>[^<]*)" + titleEnd.Replace("(", "\\(").Replace(")", "\\)") + "[\\s\\S]+" + contentStart.Replace("(", "\\(").Replace(")", "\\)") + "(?<content>[\\s\\S]+)" + contetnEnd.Replace("(", "\\(").Replace(")", "\\)"), RegexOptions.IgnoreCase | RegexOptions.Multiline);
                        Match mat = reg.Match(GetHttpData(s, "gb2312"));
                        //Response.Write(string.Format("news:{0}<br>content:{1}<br>",mat.Groups["title"].Value,mat.Groups["content"].Value));
                        Beans.News news = new Beans.News();
                        news.Title = mat.Groups["title"].Value;
                        news.Typeid = Convert.ToString(Request["Gid"]);//mat.Groups["title"].Value;
                        news.From = this.TbSiteName.Text;//mat.Groups["content"].Value;
                        news.Content = mat.Groups["content"].Value;
                        news.Add();
                        sb.AppendFormat("title:{0}", mat.Groups["title"].Value);
                    }
                }
                return sb.ToString();
            }
            public string GetHttpData(string sUrl, string encoding)
            {
                string sRslt = null;
                WebResponse oWebRps = null;
                WebRequest oWebRqst = WebRequest.Create(sUrl);
                oWebRqst.Timeout = 50000;
                try
                {
                    oWebRps = oWebRqst.GetResponse();
                }

                finally
                {
                    if (oWebRps != null)
                    {
                        StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), System.Text.Encoding.GetEncoding(encoding));
                        sRslt = oStreamRd.ReadToEnd();
                        oStreamRd.Close();
                        oWebRps.Close();
                    }
                }
                return sRslt;
            }

        

       
        }
    }

     

    posted on 2009-07-18 15:08 sanmao 閱讀(236) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲av永久无码一区二区三区| 四虎国产精品成人免费久久| 国产成人免费全部网站| sss在线观看免费高清| 亚洲男人第一av网站| 韩国欧洲一级毛片免费| baoyu777永久免费视频| 中文字幕 亚洲 有码 在线| 亚洲不卡AV影片在线播放| 久久成人免费播放网站| 久久人午夜亚洲精品无码区| 亚洲乱码中文字幕综合| 日韩一区二区a片免费观看| GOGOGO高清免费看韩国| 亚洲乱码国产乱码精华| 亚洲va无码va在线va天堂| 国产在线观看免费不卡| 亚洲国产精品免费在线观看| 日韩电影免费在线观看网址 | 巨胸喷奶水www永久免费| 亚洲综合男人的天堂色婷婷| 亚洲国产精品尤物YW在线观看| 91九色精品国产免费| 91成人免费福利网站在线| 亚洲精品久久久久无码AV片软件| 亚洲av成人无码久久精品| av无码东京热亚洲男人的天堂| 可以免费看黄的网站| 久久免费视频一区| 国产成人综合亚洲一区| 亚洲人成网男女大片在线播放| 国产亚洲精品精华液| 免费一级特黄特色大片在线观看| 手机看黄av免费网址| 亚洲免费精彩视频在线观看| 99视频在线免费| 国产大片免费天天看| 美女被吸屁股免费网站| 亚洲无人区码一二三码区别图片 | 亚洲国产成人精品久久| 亚洲日韩精品无码专区网址|