diff --git a/Form1.Designer.cs b/Form1.Designer.cs index f7d90e9..686c54f 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -452,7 +452,7 @@ private void InitializeComponent() this.ClientSize = new System.Drawing.Size(800, 501); this.Controls.Add(this.tabPages); this.Name = "Form1"; - this.Text = "갤창랭킹.v2.0.9.2"; + this.Text = "갤창랭킹.v2.0.9.3"; this.Load += new System.EventHandler(this.Form1_Load); this.dataToText.ResumeLayout(false); this.dataToText.PerformLayout(); diff --git a/Form1.cs b/Form1.cs index 1bf9489..e586a9d 100644 --- a/Form1.cs +++ b/Form1.cs @@ -15,7 +15,7 @@ namespace DcCrawler.WF { public partial class Form1 : Form { - public string version = "v2.0.9.2"; + public string version = "v2.0.9.3"; public Form1() { InitializeComponent(); @@ -115,8 +115,13 @@ private void gcrkStart_Click(object sender, EventArgs e) textConsole.AppendText("갤창랭킹\r\n"); gcrk.newPageHappened += NewPageUpdate; gcrk.CrawlingEnded += UserListUpdate; + gcrk.ErrorOccured += ErrorMessage; gcrk.Crawler(); } + private void ErrorMessage(object sender, EventArgs e) + { + textConsole.AppendText((string)sender); + } string filename = ""; hdc.DataToText dtt; private void callFileListBtn_Click(object sender, EventArgs e) diff --git a/gallchangranking.cs b/gallchangranking.cs index 32194f6..d7158ec 100644 --- a/gallchangranking.cs +++ b/gallchangranking.cs @@ -282,6 +282,7 @@ public class GallchangrankingCrawler public event EventHandler newPageHappened; public event EventHandler CrawlingEnded; public event EventHandler NewVersionUpdateExist; + public event EventHandler ErrorOccured; int initPage, endPage; DateTime initDate, endDate; @@ -373,7 +374,20 @@ public void Crawler() int currentPage = this.initPage; while (true) { - string text = client.DownloadString(url + currentPage.ToString()); + string text; + try + { + text = client.DownloadString(url + currentPage.ToString()); + if (string.IsNullOrEmpty(text)) + { + continue; + } + } + catch + { + continue; + } + hap.HtmlDocument textHap = new hap.HtmlDocument(); textHap.LoadHtml(text); @@ -381,84 +395,96 @@ public void Crawler() hap.HtmlNodeCollection nicks = textHap.DocumentNode.SelectNodes("//tr[@class='ub-content us-post']"); //Console.WriteLine(nicks.Count); //Console.WriteLine("==================" + currentPage.ToString() + "=================="); - - foreach (hap.HtmlNode nick in nicks) + try { - int gallNum, replyNum, gallCount, gallRecommend; - DateTime gallDate; string subject; - - gallNum = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_num']").InnerText); - gallDate = DateTime.ParseExact(nick.SelectSingleNode("./td[@class='gall_date']").Attributes["title"].Value, - "yyyy-MM-dd HH:mm:ss", null); - Console.WriteLine(gallNum.ToString() + " " + gallDate.ToString()); - if (gallNum >= previousPageGallNum) - { - Console.WriteLine(previousPageGallNum.ToString() + " " + gallNum.ToString()); - Console.WriteLine("번호 에러"); - continue; - } - if (DateTime.Compare(gallDate, initDate) < 0 || DateTime.Compare(gallDate, endDate) > 0) + foreach (hap.HtmlNode nick in nicks) { - Console.WriteLine("날짜 에러"); - continue; - } - - hap.HtmlNode user = nick.SelectSingleNode("./td[@class='gall_writer ub-writer']"); - UserInfo tempUserInfo = new UserInfo(user.Attributes["data-nick"].Value); - if (user.Attributes["data-uid"].Value == "") - { - tempUserInfo.setFluidNick(user.Attributes["data-ip"].Value); - } - else - { - tempUserInfo.setFixedNick(user.Attributes["data-uid"].Value); - } + int gallNum, replyNum, gallCount, gallRecommend; + DateTime gallDate; string subject; - //replyNum and subject are in - hap.HtmlNode subjectNode = nick.SelectSingleNode("./td[2]"); - try - { - if (subjectNode.Attributes["class"].Value == "gall_subject") + gallNum = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_num']").InnerText); + gallDate = DateTime.ParseExact(nick.SelectSingleNode("./td[@class='gall_date']").Attributes["title"].Value, + "yyyy-MM-dd HH:mm:ss", null); + Console.WriteLine(gallNum.ToString() + " " + gallDate.ToString()); + if (gallNum >= previousPageGallNum) { - subjectNode = nick.SelectSingleNode("./td[3]"); + Console.WriteLine(previousPageGallNum.ToString() + " " + gallNum.ToString()); + Console.WriteLine("번호 에러"); + continue; } - subject = subjectNode.SelectSingleNode("./a[1]").InnerText; - if (subjectNode.SelectNodes("./a").Count == 2) + if (DateTime.Compare(gallDate, initDate) < 0 || DateTime.Compare(gallDate, endDate) > 0) + { + Console.WriteLine("날짜 에러"); + continue; + } + + hap.HtmlNode user = nick.SelectSingleNode("./td[@class='gall_writer ub-writer']"); + UserInfo tempUserInfo = new UserInfo(user.Attributes["data-nick"].Value); + if (user.Attributes["data-uid"].Value == "") { - replyNum = GetOnlyInt(subjectNode.SelectSingleNode("./a[@class='reply_numbox']/span").InnerText); + tempUserInfo.setFluidNick(user.Attributes["data-ip"].Value); } else { + tempUserInfo.setFixedNick(user.Attributes["data-uid"].Value); + } + + //replyNum and subject are in + hap.HtmlNode subjectNode = nick.SelectSingleNode("./td[2]"); + try + { + if (subjectNode.Attributes["class"].Value == "gall_subject") + { + subjectNode = nick.SelectSingleNode("./td[3]"); + } + subject = subjectNode.SelectSingleNode("./a[1]").InnerText; + if (subjectNode.SelectNodes("./a").Count == 2) + { + replyNum = GetOnlyInt(subjectNode.SelectSingleNode("./a[@class='reply_numbox']/span").InnerText); + } + else + { + replyNum = 0; + } + } + catch + { + subject = "NullSubjectException"; replyNum = 0; } - } - catch - { - subject = "NullSubjectException"; - replyNum = 0; - } - // Console.WriteLine("댓글: " + replyNum.ToString()); - gallCount = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_count']").InnerText); - gallRecommend = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_recommend']").InnerText); + // Console.WriteLine("댓글: " + replyNum.ToString()); + gallCount = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_count']").InnerText); + gallRecommend = GetOnlyInt(nick.SelectSingleNode("./td[@class='gall_recommend']").InnerText); - //Dictionary value => count, replyNum, gallCount, gallRecommend - if (userDic.ContainsKey(tempUserInfo)) - { - userDic[tempUserInfo][0] += 1; - userDic[tempUserInfo][1] += replyNum; - userDic[tempUserInfo][2] += gallCount; - userDic[tempUserInfo][3] += gallRecommend; + //Dictionary value => count, replyNum, gallCount, gallRecommend + if (userDic.ContainsKey(tempUserInfo)) + { + userDic[tempUserInfo][0] += 1; + userDic[tempUserInfo][1] += replyNum; + userDic[tempUserInfo][2] += gallCount; + userDic[tempUserInfo][3] += gallRecommend; + } + else + { + int[] tempInts = new int[] { 1, replyNum, gallCount, gallRecommend }; + userDic.Add(tempUserInfo, tempInts); + } + UserData tempUserData = new UserData(tempUserInfo); + tempUserData.DataInput(gallNum, replyNum, gallCount, gallRecommend, gallDate, subject); + //gallDatas.Add(tempUserData); } - else + } + catch + { + if(ErrorOccured != null) { - int[] tempInts = new int[] { 1, replyNum, gallCount, gallRecommend }; - userDic.Add(tempUserInfo, tempInts); + ErrorOccured(text, null); } - UserData tempUserData = new UserData(tempUserInfo); - tempUserData.DataInput(gallNum, replyNum, gallCount, gallRecommend, gallDate, subject); - //gallDatas.Add(tempUserData); + currentPage++; + continue; } + previousPageGallNum = GetOnlyInt(nicks[nicks.Count - 1].SelectSingleNode("./td[@class='gall_num']").InnerText); DateTime currentDate = DateTime.ParseExact(nicks[nicks.Count - 1]. SelectSingleNode("./td[@class='gall_date']").Attributes["title"].Value, "yyyy-MM-dd HH:mm:ss", null); diff --git a/versions.txt b/versions.txt index 20cdd9e..9b38b7d 100644 --- a/versions.txt +++ b/versions.txt @@ -1,3 +1,4 @@ +v2.0.9.3 v2.0.9.2 v2.0.9.1 v2.0.9