Пример #1
0
 private void btnonekeygather_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.txturlgather.Text.Trim().Length < 1)
         {
             MessageBox.Show("网址不能为空!");
             this.txturlgather.Focus();
         }
         else
         {
             string pattern = "(http|https)://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
             Match  match   = Regex.Match(this.txturlgather.Text, pattern);
             if (!match.Success)
             {
                 MessageBox.Show("请输入正确的网址");
                 this.txturlgather.Focus();
             }
             else
             {
                 this.urltxt = this.txturlgather.Text.Trim();
                 if (!this.urltxt.EndsWith("/"))
                 {
                     this.urltxt += "/";
                 }
                 string html = "";
                 try
                 {
                     html = NetHelper.HttpGet(this.urltxt, "", Encoding.GetEncoding("UTF-8"));
                 }
                 catch (Exception ex)
                 {
                     string pattern2 = "(http|https)://(?<domain>[^(:|/]*)";
                     Match  match2   = Regex.Match(this.txturlgather.Text, pattern2);
                     this.urltxt = match2.Groups[0].ToString();
                     if (!this.urltxt.EndsWith("/"))
                     {
                         this.urltxt += "/";
                     }
                     html = NetHelper.HttpGet(this.urltxt, "", Encoding.GetEncoding("UTF-8"));
                 }
                 if (this.isLuan(html))
                 {
                     html = NetHelper.HttpGet(this.urltxt, "", Encoding.GetEncoding("gb2312"));
                 }
                 List <gather>   list            = new List <gather>();
                 string          pattern3        = "(?is)<a(?:(?!href=).)*href=(['\"]?)(?<url>[^\"\\s>]*)\\1[^>]*>(?<text>(?:(?!</?a\\b).)*)</a>";
                 MatchCollection matchCollection = Regex.Matches(html, pattern3, RegexOptions.Multiline);
                 foreach (Match match3 in matchCollection)
                 {
                     string input = Regex.Replace(match3.Groups["text"].Value, "<[^>]*>", string.Empty);
                     string title = Regex.Replace(input, "\\s", "").Replace("&nbsp;", "").Replace("&quot", "").Replace("&raquo", "");
                     if (Encoding.Default.GetByteCount(title) > 17)
                     {
                         gather gather = new gather();
                         gather.title = title;
                         string url = match3.Groups["url"].Value;
                         if (!string.IsNullOrEmpty(url))
                         {
                             if (url.StartsWith("http://") || url.StartsWith("https://"))
                             {
                                 gather.url = url;
                             }
                             else
                             {
                                 string pattern2 = "(http|https)://(?<domain>[^(:|/]*)";
                                 Match  match2   = Regex.Match(this.txturlgather.Text, pattern2);
                                 this.urltxt = match2.Groups[0].ToString();
                                 if (!this.urltxt.EndsWith("/"))
                                 {
                                     this.urltxt += "/";
                                 }
                                 gather.url = this.urltxt + url;
                             }
                             gather.isdeal = "---";
                             list.Add(gather);
                         }
                     }
                 }
                 this.dgvtitlegather.AutoGenerateColumns = false;
                 this.dgvtitlegather.DataSource          = list;
                 MessageBox.Show("抓取文章共" + this.dgvtitlegather.Rows.Count + "篇");
                 this.label60.Text = "文章数量:" + this.dgvtitlegather.Rows.Count + "篇";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("采集失败,请更换网址" + ex);
     }
 }
Пример #2
0
        private void LoginServer(string name, string pass)
        {
            string   realmList = "";      //目前所有站
            string   realmNameInfo = "";  //权限站
            string   expirationTime = ""; //到期时间
            DateTime s, n;

            s = DateTime.Now;
            n = DateTime.Now;

            string key = NetHelper.GetMD5(name + "100dh888");
            string dosubmit = "1";
            //var obj = new
            //{
            //    username = name,
            //    password = pass,
            //    dosubmit,
            //    key
            //};
            //string postDataStr = JsonConvert.SerializeObject(obj);
            StringBuilder strpost = new StringBuilder();

            strpost.AppendFormat("username={0}&", name);
            strpost.AppendFormat("password={0}&", pass);
            strpost.AppendFormat("dosubmit={0}&", dosubmit);
            strpost.AppendFormat("key={0}&", key);
            try
            {
                string login_json = NetHelper.HttpPost("http://tool.100dh.cn/LoginHandler.ashx?action=Login", strpost.ToString());
                if (login_json != "")
                {
                    // list = (List<CategoryJson>)HttpHelper.JsonToObject<List<CategoryJson>>(main1);
                    JObject jo   = (JObject)JsonConvert.DeserializeObject(login_json);
                    string  code = jo["code"].ToString();
                    string  msg  = jo["msg"].ToString();
                    if (code == "0")//失败
                    {
                        MessageBox.Show("登录失败," + msg); return;
                    }
                    else if (code == "1")//成功
                    {
                        string data = jo["detail"].ToString();
                        expirationTime = jo["detail"]["cmUser"]["expirationTime"].ToString(); //到期时间
                        DateTime.TryParse(expirationTime, out s);
                        realmNameInfo = jo["detail"]["cmUser"]["realmNameInfo"].ToString();   //此账号下绑定的域名
                        realmList     = jo["detail"]["realmList"].ToString();
                        //rjlist = (List<ReleaseJson>)HttpHelper.JsonToObject<List<ReleaseJson>>(release);
                        List <realmNameInfo> rjlist = (List <realmNameInfo>)HttpHelper.JsonToObject <List <realmNameInfo> >(realmList);
                        if (rjlist.Count > 0)
                        {
                            List <realmNameInfo> rList = new List <realmNameInfo>();
                            foreach (realmNameInfo rj in rjlist)
                            {
                                //rj.path = joo[item.Key]["path"].ToString();路径,暂时未加
                                if (realmNameInfo.Contains(rj.Id) && rj.isUseing == true)
                                {
                                    rList.Add(rj);
                                }
                            }
                            Myinfo.rjlist = rList;
                        }
                        if (s <= n)
                        {
                            MessageBox.Show("授权已到期!");
                        }
                        else
                        {
                            Myinfo.softtime      = s - n;
                            Myinfo.realmNameInfo = realmNameInfo;
                            Myinfo.username      = name;
                            Myinfo.password      = pass;
                            if (ckbremenber.Checked)
                            {
                                AShelp.Save(this.txtName.Text, this.txtPwd.Text, "", "", "user");
                                Myinfo.username = this.txtName.Text;
                            }
                            frmMain f = new frmMain(name, pass);
                            f.Show();
                            Myinfo.myfmain = f;
                            Myinfo.mylogin = this;
                            this.Hide();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误,请联系作者!" + ex);
            }
        }