Skip to content

Commit

Permalink
v2.0.9.3-Error Fixed
Browse files Browse the repository at this point in the history
갤창랭킹 도중 에러 처리,
통신사 ip 목록 업데이트
  • Loading branch information
unknown committed Oct 31, 2019
1 parent 2384cb0 commit f170535
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
150 changes: 88 additions & 62 deletions gallchangranking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -373,92 +374,117 @@ 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);

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 <td class='gall_tit ub-word'></td>
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 <td class='gall_tit ub-word'></td>
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);
Expand Down
1 change: 1 addition & 0 deletions versions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
v2.0.9.3
v2.0.9.2
v2.0.9.1
v2.0.9
Expand Down

0 comments on commit f170535

Please sign in to comment.