Ejemplo n.º 1
0
        //开始删除
        private void simpleButton2_Click_bak(object sender, EventArgs e)
        {
            if (gridView5.DataSource != null)
            {
                DataTable dt = ((DataView)gridView5.DataSource).ToTable();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        NameValueCollection dic = new NameValueCollection();
                        CookieContainer     cc  = new CookieContainer();
                        dic.Add("weburl", dr["url"].ToString());
                        dic.Add("search_submit", " 搜 索 ");
                        if (hash.ContainsKey(dr["mburl"]))
                        {
                            Cookie c = new Cookie("PHPSESSID", hash[dr["mburl"]].ToString().Split('=')[1]);
                            cc.Add(new Uri(dr["mburl"].ToString()), c);
                            HtmlAgilityPack.HtmlDocument doc = HttpUtils.HtmlPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?pnum=100", dic, cc);
                            //总页数
                            int[] info  = CrawlerCenter.GetLinkPages(doc);
                            int   pages = info == null ? 0 : info[0];
                            int   total = info == null ? 0 : info[1];
                            NameValueCollection deleteRows = new NameValueCollection();
                            for (int i = 1; i <= pages; i++)
                            {
                                if (i == 1)
                                {
                                    deleteRows = CrawlerCenter.GetDeleteIds(doc);
                                    bool flag = HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", deleteRows, cc);
                                    if (flag)
                                    {
                                        DeleteArticleSuccess.Add(dr["mburl"], true);
                                    }
                                }
                                else
                                {
                                    NameValueCollection ids = HttpUtils.ListPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic, cc);
                                    HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", ids, cc);
                                }
                            }


                            //NameValueCollection ids = HttpUtils.ListPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?pnum=100", dic, cc);
                            //bool flag = HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", ids, cc);
                            //progressBarControl1.Position += 1;
                            //if (flag)
                            //    dr["status"] = "成功";
                            //else
                            //    dr["status"] = "失败";
                            //gridControl5.DataSource = dt;
                            //Application.DoEvents();
                        }
                        else
                        {
                            MessageBox.Show("请先登录网站!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="requestUri"></param>
        /// <param name="postData"></param>
        /// <returns></returns>
        public static System.Collections.Specialized.NameValueCollection ListPost(string requestUri, NameValueCollection postData, CookieContainer cc)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
                request.Method          = "post";
                request.ContentType     = "application/x-www-form-urlencoded";
                request.CookieContainer = cc;
                request.Timeout         = 10000;
                request.KeepAlive       = false;
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string key in postData.Keys)
                {
                    stringBuilder.AppendFormat("&{0}={1}", key, postData.Get(key));
                }
                byte[] buffer        = Encoding.UTF8.GetBytes(stringBuilder.ToString().Trim('&'));
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(buffer, 0, buffer.Length);
                requestStream.Close();

                WebResponse  response = request.GetResponse();
                StreamReader reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string       html     = reader.ReadToEnd();//读取数据
                HtmlDocument doc      = new HtmlDocument();
                doc.LoadHtml(html);

                System.Collections.Specialized.NameValueCollection dic = CrawlerCenter.GetDeleteIds(doc);
                return(dic);
            }
            catch (Exception e1)
            {
                Console.WriteLine("ListPost异常:" + e1.Message);
                return(null);
            }
        }
Ejemplo n.º 3
0
        private void muiltiDeleteArticle2(object o)
        {
            DataRow dr = _Delete.NewRow();

            dr = (DataRow)o;
            NameValueCollection dic = new NameValueCollection();
            CookieContainer     cc  = new CookieContainer();

            dic.Add("weburl", dr["url"].ToString());
            dic.Add("search_submit", " 搜 索 ");
            if (hash.ContainsKey(dr["mburl"]))
            {
                Cookie c = new Cookie("PHPSESSID", hash[dr["mburl"]].ToString().Split('=')[1]);
                cc.Add(new Uri(dr["mburl"].ToString()), c);
                HtmlAgilityPack.HtmlDocument doc = HttpUtils.HtmlPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?pnum=100", dic, cc);
                //总页数
                int[] info  = CrawlerCenter.GetLinkPages(doc);
                int   pages = info == null ? 0 : info[0];
                int   total = info == null ? 0 : info[1];
                NameValueCollection deleteRows = new NameValueCollection();
                for (int i = 1; i <= pages; i++)
                {
                    if (i == 1)
                    {
                        deleteRows = CrawlerCenter.GetDeleteIds(doc);
                        bool flag = HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", deleteRows, cc);
                    }
                    else
                    {
                        NameValueCollection ids = HttpUtils.ListPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic, cc);
                        HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", ids, cc);
                    }
                }


                //NameValueCollection ids = HttpUtils.ListPost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/list.php?pnum=100", dic, cc);
                //bool flag = HttpUtils.deletePost(dr["mburl"].ToString() + ht[dr["mburl"]] + "/link/set.php", ids, cc);
                //progressBarControl1.Position += 1;
                //if (flag)
                //    dr["status"] = "成功";
                //else
                //    dr["status"] = "失败";
                //gridControl5.DataSource = dt;
                //Application.DoEvents();
            }
            else
            {
                Console.WriteLine("请先登录网站!");
            }
        }
Ejemplo n.º 4
0
        private void muiltiDeleteColumn(object o)
        {
            DataRow dr = _dt.NewRow();

            dr = (DataRow)o;

            NameValueCollection dic = new NameValueCollection();
            CookieContainer     cc  = new CookieContainer();

            dic.Add("colid", "0");
            dic.Add("pos", "2");
            if (hash.ContainsKey(dr["wz"]))
            {
                Console.WriteLine(dr["wz"] + "开始执行。。。");
                Cookie c = new Cookie("PHPSESSID", hash[dr["wz"]].ToString().Split('=')[1]);
                cc.Add(new Uri(dr["wz"].ToString()), c);
                HtmlAgilityPack.HtmlDocument doc = HttpUtils.HtmlPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?pnum=100", dic, cc);
                //总页数
                int[] info  = CrawlerCenter.GetLinkPages(doc);
                int   pages = info == null ? 0 : info[0];
                int   total = info == null ? 0 : info[1];
                NameValueCollection deleteRows = new NameValueCollection();
                for (int i = 1; i <= pages; i++)
                {
                    if (i == 1)
                    {
                        deleteRows = CrawlerCenter.GetDeleteIds(doc);
                        bool flag = HttpUtils.deletePost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/set.php", deleteRows, cc);
                        if (flag)
                        {
                            DeleteColumnSuccess.Add(dr["wz"], true);
                        }
                    }
                    else
                    {
                        NameValueCollection ids = HttpUtils.ListPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic, cc);
                        HttpUtils.deletePost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/set.php", ids, cc);
                    }
                }
                Console.WriteLine(dr["wz"] + "执行完毕。。。");
            }
        }
Ejemplo n.º 5
0
        private void muiltiDeleteWebName(object o)
        {
            DataRow dr = _Delete.NewRow();

            dr = (DataRow)o;
            NameValueCollection dic = new NameValueCollection();
            CookieContainer     cc  = new CookieContainer();

            dic.Add("webname", "http");
            dic.Add("search_submit", " 搜 索 ");
            if (hash.ContainsKey(dr["wz"]))
            {
                Cookie c = new Cookie("PHPSESSID", hash[dr["wz"]].ToString().Split('=')[1]);
                cc.Add(new Uri(dr["wz"].ToString()), c);
                HtmlAgilityPack.HtmlDocument doc = HttpUtils.HtmlPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?pnum=100", dic, cc);
                //总页数
                int[] info  = CrawlerCenter.GetLinkPages(doc);
                int   pages = info == null ? 0 : info[0];
                int   total = info == null ? 0 : info[1];
                NameValueCollection deleteRows = new NameValueCollection();
                for (int i = 1; i <= pages; i++)
                {
                    if (i == 1)
                    {
                        deleteRows = CrawlerCenter.GetDeleteIds(doc);
                        bool flag = HttpUtils.deletePost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/set.php", deleteRows, cc);
                    }
                    else
                    {
                        NameValueCollection ids = HttpUtils.ListPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic, cc);
                        HttpUtils.deletePost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/set.php", ids, cc);
                    }
                }
            }
            else
            {
                Console.WriteLine("请先登录网站!");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 删除不带http的链接
        /// </summary>
        /// <param name="o"></param>
        private void muiltiDeleteNoHttp(object o)
        {
            try
            {
                DataRow dr = _Delete.NewRow();
                dr = (DataRow)o;
                NameValueCollection dic     = new NameValueCollection();
                NameValueCollection dic_all = new NameValueCollection();
                CookieContainer     cc      = new CookieContainer();
                dic.Add("weburl", "http");
                dic.Add("search_submit", " 搜 索 ");
                dic_all.Add("search_submit", " 搜 索 ");
                if (hash.ContainsKey(dr["wz"]))
                {
                    Cookie c = new Cookie("PHPSESSID", hash[dr["wz"]].ToString().Split('=')[1]);
                    cc.Add(new Uri(dr["wz"].ToString()), c);
                    Console.WriteLine(dr["wz"] + " 开始执行。。。。。。。。。。");
                    //查询所有的IDS
                    HtmlAgilityPack.HtmlDocument doc_all = HttpUtils.HtmlPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?pnum=100", dic_all, cc);
                    //查询带http的IDS
                    HtmlAgilityPack.HtmlDocument doc = HttpUtils.HtmlPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?pnum=100", dic, cc);

                    #region + 获取所有链接的IDS
                    int[] info_all  = CrawlerCenter.GetLinkPages(doc_all);
                    int   pages_all = info_all == null ? 0 : info_all[0];
                    int   total_all = info_all == null ? 0 : info_all[1];
                    NameValueCollection   deleteRows_all_1 = new NameValueCollection();
                    NameValueCollection   deleteRows_all_e = new NameValueCollection();
                    NameValueCollection[] paras            = new NameValueCollection[pages_all];
                    for (int i = 1; i <= pages_all; i++)
                    {
                        if (i == 1)
                        {
                            deleteRows_all_1 = CrawlerCenter.GetDeleteIds(doc_all);
                            if (deleteRows_all_1 != null)
                            {
                                paras[0] = deleteRows_all_1;
                            }
                        }
                        else
                        {
                            deleteRows_all_e = HttpUtils.ListPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic_all, cc);
                            if (deleteRows_all_e != null)
                            {
                                paras[i - 1] = deleteRows_all_e;
                            }
                        }
                    }
                    NameValueCollection all_ids = CrawlerCenter.Merge(paras);
                    #endregion
                    #region + 获取带http的链接的IDS
                    //总页数
                    int[] info  = CrawlerCenter.GetLinkPages(doc);
                    int   pages = info == null ? 0 : info[0];
                    int   total = info == null ? 0 : info[1];
                    NameValueCollection   deleteRows_1 = new NameValueCollection();
                    NameValueCollection   deleteRows_e = new NameValueCollection();
                    NameValueCollection[] paras_       = new NameValueCollection[pages];
                    for (int i = 1; i <= pages; i++)
                    {
                        if (i == 1)
                        {
                            deleteRows_1 = CrawlerCenter.GetDeleteIds(doc);
                            if (deleteRows_1 != null)
                            {
                                paras_[0] = deleteRows_1;
                            }
                        }
                        else
                        {
                            deleteRows_e = HttpUtils.ListPost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/list.php?action=link&pnum=100&page=" + i, dic, cc);
                            if (deleteRows_e != null)
                            {
                                paras_[i - 1] = deleteRows_e;
                            }
                        }
                    }
                    NameValueCollection ids      = CrawlerCenter.Merge(paras_);
                    NameValueCollection finalIds = CrawlerCenter.Duplicate(all_ids, ids);
                    Console.WriteLine(dr["wz"] + "找到未含有http链接个数:" + finalIds.Count + "个");
                    if (finalIds.Count > 0)
                    {
                        HttpUtils.deletePost(dr["wz"].ToString() + ht[dr["wz"]] + "/link/set.php", finalIds, cc);
                    }
                    Console.WriteLine(dr["wz"] + "执行完毕。");
                    #endregion
                }
                else
                {
                    Console.WriteLine("请先登录网站!");
                }
            }
            catch (Exception e1) { Console.WriteLine("发生异常:" + e1.Message); }
        }
Ejemplo n.º 7
0
 private void 获取友链ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (gridView1.DataSource != null)
     {
         DataTable dt        = ((DataView)gridView1.DataSource).ToTable();
         DataTable dt_column = new DataTable();
         dt_column.Columns.Add("id", typeof(string));
         dt_column.Columns.Add("url", typeof(string));
         dt_column.Columns.Add("zxurl", typeof(string));
         dt_column.Columns.Add("show", typeof(string));
         dt_column.Columns.Add("status", typeof(string));
         DataRow dr_col = dt_column.NewRow();
         if (dt != null && dt.Rows.Count > 0)
         {
             foreach (DataRow dr in dt.Rows)
             {
                 if (dr["zt"] != null && dr["zt"].ToString() == "登录成功")
                 {
                     string cookie = hash[dr["wz"]].ToString();
                     label1.Text = dr["wz"].ToString();
                     Application.DoEvents();
                     string html = HttpUtils.DownloadUrl(dr["wz"].ToString() + dr["lj"].ToString() + "/link/list.php?action=link&pnum=1000", cookie);
                     HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                     doc.LoadHtml(html);
                     //总页数
                     int[] info  = CrawlerCenter.GetLinkPages(doc);
                     int   pages = info[0];
                     int   total = info[1];
                     progressBarControl1.Properties.Maximum   = total;
                     progressBarControl1.Properties.Minimum   = 0;
                     progressBarControl1.Properties.ShowTitle = true;
                     progressBarControl1.Position             = 0;
                     for (int i = 1; i <= pages; i++)
                     {
                         Link col = new Link();
                         for (int j = 1; j <= 1000; j++)
                         {
                             col = new Link();
                             if (i == 1)
                             {
                                 col = CrawlerCenter.GetLinks(doc, j);
                             }
                             else
                             {
                                 if (j == 1)
                                 {
                                     html = HttpUtils.DownloadUrl(dr["wz"].ToString() + dr["lj"].ToString() + "/link/list.php?action=link&page=" + i + "&pnum=1000", cookie);
                                     doc  = new HtmlAgilityPack.HtmlDocument();
                                     doc.LoadHtml(html);
                                 }
                                 col = CrawlerCenter.GetLinks(doc, j);
                             }
                             if (col != null && !string.IsNullOrEmpty(col.Id))
                             {
                                 progressBarControl1.Position += 1;
                                 dr_col           = dt_column.NewRow();
                                 dr_col["id"]     = col.Id.Trim();
                                 dr_col["url"]    = col.Url;
                                 dr_col["zxurl"]  = col.ZxUrl;
                                 dr_col["show"]   = col.Show;
                                 dr_col["status"] = col.Status;
                                 dt_column.Rows.Add(dr_col);
                                 //加入列表
                                 gridControl3.DataSource = dt_column;
                                 Application.DoEvents();
                             }
                             else
                             {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("请先登录网站!");
     }
 }