예제 #1
0
        public ArticleInfo DeleteArticle(ArticleInfo info, GalleryType gallType, bool both)
        {
            // HTTP 요청에 딜레이를 주어 서버 오류 방지
            int delay = 50;

            DeleteResult res1 = null;

            try
            {
                if (IsLogin)
                {
                    res1 = HttpRequest.RequestDeleteArticle(info.GalleryArticleDeleteParameters, gallType, delay, ref cookies);
                }
                else
                {
                    res1 = HttpRequest.RequestDeleteFlowArticle(info.GalleryArticleDeleteParameters, gallType, delay, ref cookies);
                }
            }
            catch (ThreadAbortException) { throw; }
            catch (Exception ex)
            {
                info.ActualDelete  = false;
                info.GallogDelete  = false;
                info.DeleteMessage = "갤러리의 글을 지우는데 실패하였습니다 - [" + ex.Message + "]";

                return(info);
            }

            if (!res1.Success && res1.ErrorMessage != "이미 삭제된 글입니다.")
            {
                info.ActualDelete  = false;
                info.GallogDelete  = false;
                info.DeleteMessage = "갤러리의 글을 지우는데 실패하였습니다 - [" + res1.ErrorMessage + "]";

                return(info);
            }

            if (both)
            {
                Thread.Sleep(delay);

                DeleteResult res2 = null;

                try
                {
                    res2 = HttpRequest.RequestDeleteGallogArticle(info.GallogArticleDeleteParameters, delay, ref cookies);
                }
                catch (ThreadAbortException) { throw; }
                catch (Exception ex)
                {
                    info.ActualDelete  = true;
                    info.GallogDelete  = false;
                    info.DeleteMessage = "갤로그의 글을 지우는데 실패하였습니다 - [" + ex.Message + "]";

                    return(info);
                }

                if (!res2.Success)
                {
                    info.ActualDelete  = true;
                    info.GallogDelete  = false;
                    info.DeleteMessage = "갤로그의 글을 지우는데 실패하였습니다 - [" + res2.ErrorMessage + "]";

                    return(info);
                }
            }

            info.ActualDelete = true;
            info.GallogDelete = true;
            return(info);
        }
예제 #2
0
        internal static List <ArticleInfo> GetSearchedArticleList(string searchedHtml, string gall_id, string searchNick, GalleryType gallType, bool isFixed, ref int searchPos, out int maxPage)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(searchedHtml);

            maxPage = 0;

            List <ArticleInfo> searchedList = new List <ArticleInfo>();

            string baseUrl = "http://gall.dcinside.com/";

            HtmlNode pageList = doc.GetElementbyId("dgn_btn_paging");

            if (pageList == null)
            {
                throw new Exception("알 수 없는 오류입니다.");
            }

            HtmlNode lastChild = pageList.Descendants("a").Last();

            if (lastChild.InnerText != "다음검색")
            {
                searchPos = -1;
            }
            else
            {
                string src = lastChild.GetAttributeValue("href", "");
                if (string.IsNullOrWhiteSpace(src))
                {
                    throw new Exception("알 수 없는 오류입니다.");
                }

                src = baseUrl + src.Substring(1);

                Uri nextSearchUri = new Uri(src);
                int.TryParse(HttpUtility.ParseQueryString(nextSearchUri.Query).Get("search_pos"), out searchPos);
            }

            HtmlNode lastPage = pageList.Descendants("span").Where(n => n.GetAttributeValue("class", "") == "arrow_2").FirstOrDefault();

            if (lastPage == null)
            {
                if (lastChild.InnerText != "다음검색")
                {
                    int.TryParse(lastChild.InnerText, out maxPage);
                }
                else
                {
                    lastPage = lastChild.PreviousSibling;
                    int.TryParse(lastPage.InnerText, out maxPage);
                }
            }
            else
            {
                string src = lastPage.ParentNode.GetAttributeValue("href", "");
                if (string.IsNullOrWhiteSpace(src))
                {
                    throw new Exception("알 수 없는 오류입니다.");
                }

                src = baseUrl + src.Substring(1);

                Uri maxPageUri = new Uri(src);
                int.TryParse(HttpUtility.ParseQueryString(maxPageUri.Query).Get("page"), out maxPage);
            }

            string deleteBasePath = null;

            if (gallType == GalleryType.Normal)
            {
                deleteBasePath = "http://gall.dcinside.com/mgallery/board/delete/?id=" + gall_id;
            }
            else if (gallType == GalleryType.Minor)
            {
                deleteBasePath = "http://gall.dcinside.com/board/delete/?id=" + gall_id;
            }

            if (deleteBasePath == null)
            {
                throw new Exception("예상치 못한 갤러리 형식입니다.");
            }

            foreach (HtmlNode article in doc.DocumentNode.Descendants("tr").Where(n => n.GetAttributeValue("class", "") == "tb"))
            {
                HtmlNode noticeNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "") == "t_notice").First();
                if (noticeNode.InnerText == "공지")
                {
                    continue;
                }

                HtmlNode userNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_writer")).First();
                string   user_id  = userNode.GetAttributeValue("user_id", "");
                if (user_id == "" && isFixed)
                {
                    continue;
                }
                else if (user_id != "" && !isFixed)
                {
                    continue;
                }

                string nick = userNode.Descendants("span").First().InnerText;
                if (nick != searchNick)
                {
                    continue;
                }

                HtmlNode subjectNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_subject")).First();

                string title = subjectNode.InnerText;

                string articleUrl = subjectNode.Descendants("a").First().GetAttributeValue("href", "");
                if (string.IsNullOrWhiteSpace(articleUrl))
                {
                    throw new Exception("알 수 없는 오류입니다.");
                }

                articleUrl = baseUrl + articleUrl.Substring(1);

                Uri    subjectUri = new Uri(articleUrl);
                string articleNo  = HttpUtility.ParseQueryString(subjectUri.Query).Get("no");

                ArticleInfo info = new ArticleInfo();
                info.Date  = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_date")).First().InnerText;
                info.Title = HttpUtility.HtmlDecode(title);
                info.GalleryArticleDeleteParameters = new GalleryArticleDeleteParameters()
                {
                    GalleryId = gall_id,
                    ArticleID = articleNo
                };
                info.DeleteURL = deleteBasePath + "&no=" + articleNo;

                searchedList.Add(info);
            }

            return(searchedList);
        }