리스트뷰 추가
뷰어 추가 쓰레드 처리
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
162
Form1.Designer.cs
generated
162
Form1.Designer.cs
generated
@@ -28,20 +28,178 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
this.lvList = new System.Windows.Forms.ListView();
|
||||||
|
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.chTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.chCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.chReference = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.chLink = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
|
this.wbView = new System.Windows.Forms.WebBrowser();
|
||||||
|
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||||
|
this.chAutoReload = new System.Windows.Forms.CheckBox();
|
||||||
|
this.chAutoSelect = new System.Windows.Forms.CheckBox();
|
||||||
|
this.tbInterval = new System.Windows.Forms.TextBox();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
||||||
|
this.splitContainer1.Panel1.SuspendLayout();
|
||||||
|
this.splitContainer1.Panel2.SuspendLayout();
|
||||||
|
this.splitContainer1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
|
// lvList
|
||||||
|
//
|
||||||
|
this.lvList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||||
|
this.chTime,
|
||||||
|
this.chTitle,
|
||||||
|
this.chCodeName,
|
||||||
|
this.chCode,
|
||||||
|
this.chReference,
|
||||||
|
this.chLink});
|
||||||
|
this.lvList.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.lvList.FullRowSelect = true;
|
||||||
|
this.lvList.GridLines = true;
|
||||||
|
this.lvList.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.lvList.MultiSelect = false;
|
||||||
|
this.lvList.Name = "lvList";
|
||||||
|
this.lvList.Size = new System.Drawing.Size(864, 157);
|
||||||
|
this.lvList.TabIndex = 0;
|
||||||
|
this.lvList.UseCompatibleStateImageBehavior = false;
|
||||||
|
this.lvList.View = System.Windows.Forms.View.Details;
|
||||||
|
this.lvList.SelectedIndexChanged += new System.EventHandler(this.lvList_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// chTime
|
||||||
|
//
|
||||||
|
this.chTime.Text = "시간";
|
||||||
|
//
|
||||||
|
// chTitle
|
||||||
|
//
|
||||||
|
this.chTitle.Text = "제목";
|
||||||
|
this.chTitle.Width = 366;
|
||||||
|
//
|
||||||
|
// chCodeName
|
||||||
|
//
|
||||||
|
this.chCodeName.Text = "종목명";
|
||||||
|
//
|
||||||
|
// chCode
|
||||||
|
//
|
||||||
|
this.chCode.Text = "종목코드";
|
||||||
|
//
|
||||||
|
// chReference
|
||||||
|
//
|
||||||
|
this.chReference.Text = "출처";
|
||||||
|
this.chReference.Width = 72;
|
||||||
|
//
|
||||||
|
// chLink
|
||||||
|
//
|
||||||
|
this.chLink.Text = "링크";
|
||||||
|
this.chLink.Width = 241;
|
||||||
|
//
|
||||||
|
// wbView
|
||||||
|
//
|
||||||
|
this.wbView.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.wbView.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.wbView.MinimumSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.wbView.Name = "wbView";
|
||||||
|
this.wbView.Size = new System.Drawing.Size(864, 644);
|
||||||
|
this.wbView.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// splitContainer1
|
||||||
|
//
|
||||||
|
this.splitContainer1.Location = new System.Drawing.Point(0, 25);
|
||||||
|
this.splitContainer1.Name = "splitContainer1";
|
||||||
|
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
|
||||||
|
//
|
||||||
|
// splitContainer1.Panel1
|
||||||
|
//
|
||||||
|
this.splitContainer1.Panel1.Controls.Add(this.lvList);
|
||||||
|
//
|
||||||
|
// splitContainer1.Panel2
|
||||||
|
//
|
||||||
|
this.splitContainer1.Panel2.Controls.Add(this.wbView);
|
||||||
|
this.splitContainer1.Size = new System.Drawing.Size(864, 805);
|
||||||
|
this.splitContainer1.SplitterDistance = 157;
|
||||||
|
this.splitContainer1.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// chAutoReload
|
||||||
|
//
|
||||||
|
this.chAutoReload.AutoSize = true;
|
||||||
|
this.chAutoReload.Checked = true;
|
||||||
|
this.chAutoReload.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
|
this.chAutoReload.Location = new System.Drawing.Point(3, 4);
|
||||||
|
this.chAutoReload.Name = "chAutoReload";
|
||||||
|
this.chAutoReload.Size = new System.Drawing.Size(76, 16);
|
||||||
|
this.chAutoReload.TabIndex = 3;
|
||||||
|
this.chAutoReload.Text = "자동 갱신";
|
||||||
|
this.chAutoReload.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// chAutoSelect
|
||||||
|
//
|
||||||
|
this.chAutoSelect.AutoSize = true;
|
||||||
|
this.chAutoSelect.Checked = true;
|
||||||
|
this.chAutoSelect.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
|
this.chAutoSelect.Location = new System.Drawing.Point(85, 4);
|
||||||
|
this.chAutoSelect.Name = "chAutoSelect";
|
||||||
|
this.chAutoSelect.Size = new System.Drawing.Size(76, 16);
|
||||||
|
this.chAutoSelect.TabIndex = 4;
|
||||||
|
this.chAutoSelect.Text = "자동 선택";
|
||||||
|
this.chAutoSelect.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// tbInterval
|
||||||
|
//
|
||||||
|
this.tbInterval.Location = new System.Drawing.Point(226, 2);
|
||||||
|
this.tbInterval.Name = "tbInterval";
|
||||||
|
this.tbInterval.Size = new System.Drawing.Size(42, 21);
|
||||||
|
this.tbInterval.TabIndex = 5;
|
||||||
|
this.tbInterval.Text = "0.5초";
|
||||||
|
this.tbInterval.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||||
|
this.tbInterval.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbInterval_KeyPress);
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(167, 5);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(53, 12);
|
||||||
|
this.label1.TabIndex = 6;
|
||||||
|
this.label1.Text = "갱신주기";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(447, 378);
|
this.ClientSize = new System.Drawing.Size(864, 829);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.tbInterval);
|
||||||
|
this.Controls.Add(this.chAutoSelect);
|
||||||
|
this.Controls.Add(this.chAutoReload);
|
||||||
|
this.Controls.Add(this.splitContainer1);
|
||||||
this.Name = "Form1";
|
this.Name = "Form1";
|
||||||
this.Text = "Form1";
|
this.Text = "News Crawler";
|
||||||
|
this.splitContainer1.Panel1.ResumeLayout(false);
|
||||||
|
this.splitContainer1.Panel2.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
|
||||||
|
this.splitContainer1.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.ListView lvList;
|
||||||
|
private System.Windows.Forms.ColumnHeader chTime;
|
||||||
|
private System.Windows.Forms.ColumnHeader chTitle;
|
||||||
|
private System.Windows.Forms.ColumnHeader chCodeName;
|
||||||
|
private System.Windows.Forms.ColumnHeader chCode;
|
||||||
|
private System.Windows.Forms.ColumnHeader chReference;
|
||||||
|
private System.Windows.Forms.ColumnHeader chLink;
|
||||||
|
private System.Windows.Forms.WebBrowser wbView;
|
||||||
|
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||||
|
private System.Windows.Forms.CheckBox chAutoReload;
|
||||||
|
private System.Windows.Forms.CheckBox chAutoSelect;
|
||||||
|
private System.Windows.Forms.TextBox tbInterval;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
94
Form1.cs
94
Form1.cs
@@ -21,19 +21,28 @@ namespace NewsCrawler
|
|||||||
public string m_strTitle;
|
public string m_strTitle;
|
||||||
public DateTime m_Time;
|
public DateTime m_Time;
|
||||||
public string m_strURL;
|
public string m_strURL;
|
||||||
|
public string m_strReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.Timers.Timer m_CrawlTimer = new System.Timers.Timer();
|
||||||
Timer m_Timer = new Timer();
|
int m_iCrawlInterval = 500;
|
||||||
|
Timer m_UITimer = new Timer();
|
||||||
List<NEWS_ITEM> m_ItemList = new List<NEWS_ITEM>();
|
List<NEWS_ITEM> m_ItemList = new List<NEWS_ITEM>();
|
||||||
|
int m_iLastItemCnt = 0;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
m_Timer.Tick+=Timer_Tick;
|
wbView.ScriptErrorsSuppressed = false;
|
||||||
m_Timer.Interval=500;
|
|
||||||
m_Timer.Start();
|
m_CrawlTimer.Elapsed+=CrawlTimer_Tick;
|
||||||
|
m_CrawlTimer.Interval=1000;
|
||||||
|
m_CrawlTimer.Start();
|
||||||
|
|
||||||
|
m_UITimer.Tick += UITimer_Tick;
|
||||||
|
m_UITimer.Interval = m_iCrawlInterval;
|
||||||
|
m_UITimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadAsiaE()
|
bool ReadAsiaE()
|
||||||
@@ -42,6 +51,8 @@ namespace NewsCrawler
|
|||||||
|
|
||||||
string strServerURL = "http://www.asiae.co.kr";
|
string strServerURL = "http://www.asiae.co.kr";
|
||||||
WebRequest request = WebRequest.Create("http://www.asiae.co.kr/news/sokbo/sokbo_left.htm");
|
WebRequest request = WebRequest.Create("http://www.asiae.co.kr/news/sokbo/sokbo_left.htm");
|
||||||
|
//request.Method = "POST";
|
||||||
|
//request.
|
||||||
request.Credentials=CredentialCache.DefaultCredentials;
|
request.Credentials=CredentialCache.DefaultCredentials;
|
||||||
|
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
@@ -67,6 +78,7 @@ namespace NewsCrawler
|
|||||||
news.m_strTitle=strTitle;
|
news.m_strTitle=strTitle;
|
||||||
news.m_Time=DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture);
|
news.m_Time=DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture);
|
||||||
news.m_strURL=strURL;
|
news.m_strURL=strURL;
|
||||||
|
news.m_strReference = "아시아경제";
|
||||||
|
|
||||||
m_ItemList.Add(news);
|
m_ItemList.Add(news);
|
||||||
|
|
||||||
@@ -85,7 +97,7 @@ namespace NewsCrawler
|
|||||||
{
|
{
|
||||||
bool bHasNew = false;
|
bool bHasNew = false;
|
||||||
|
|
||||||
string strServerURL = "http://www.etoday.co.kr";
|
//string strServerURL = "http://www.etoday.co.kr";
|
||||||
WebRequest request = WebRequest.Create("http://www.etoday.co.kr/news/flash/flash_list.php?tab=2");
|
WebRequest request = WebRequest.Create("http://www.etoday.co.kr/news/flash/flash_list.php?tab=2");
|
||||||
request.Credentials=CredentialCache.DefaultCredentials;
|
request.Credentials=CredentialCache.DefaultCredentials;
|
||||||
|
|
||||||
@@ -113,6 +125,7 @@ namespace NewsCrawler
|
|||||||
news.m_strTitle=strTitle;
|
news.m_strTitle=strTitle;
|
||||||
news.m_Time=DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture);
|
news.m_Time=DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture);
|
||||||
news.m_strURL=strURL;
|
news.m_strURL=strURL;
|
||||||
|
news.m_strReference = "이투데이";
|
||||||
|
|
||||||
m_ItemList.Add(news);
|
m_ItemList.Add(news);
|
||||||
|
|
||||||
@@ -127,24 +140,69 @@ namespace NewsCrawler
|
|||||||
return bHasNew;
|
return bHasNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Timer_Tick(object sender, EventArgs e)
|
private void CrawlTimer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
bool bHasNew1 = ReadAsiaE();
|
m_CrawlTimer.Enabled = false;
|
||||||
bool bHasNew2 = ReadEtoday();
|
|
||||||
|
|
||||||
if(bHasNew1 ||bHasNew2)
|
if(chAutoReload.Checked == true)
|
||||||
{
|
{
|
||||||
m_ItemList.Sort((NEWS_ITEM news1, NEWS_ITEM news2) => news1.m_Time.CompareTo(news2.m_Time));
|
ReadAsiaE();
|
||||||
|
ReadEtoday();
|
||||||
foreach(var item in m_ItemList)
|
|
||||||
{
|
|
||||||
string strResult = string.Format("[{0}] {1} ({2})", item.m_Time, item.m_strTitle, item.m_strURL);
|
|
||||||
Console.WriteLine(strResult);
|
|
||||||
System.IO.File.AppendAllText("output.txt", strResult+"\n", Encoding.GetEncoding("EUC-KR"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_CrawlTimer.Interval = m_iCrawlInterval;
|
||||||
|
m_CrawlTimer.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UITimer_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (m_iLastItemCnt == m_ItemList.Count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_ItemList.Sort((NEWS_ITEM news1, NEWS_ITEM news2) => news1.m_Time.CompareTo(news2.m_Time));
|
||||||
|
|
||||||
|
foreach (var item in m_ItemList)
|
||||||
|
{
|
||||||
|
string strResult = string.Format("[{0}] {1} ({2})", item.m_Time, item.m_strTitle, item.m_strURL);
|
||||||
|
lvList.Items.Add(new ListViewItem(new string[] { item.m_Time.ToString("HH:mm:ss"), item.m_strTitle, "", "", item.m_strReference, item.m_strURL }));
|
||||||
|
|
||||||
|
//Console.WriteLine(strResult);
|
||||||
|
//System.IO.File.AppendAllText("output.txt", strResult+"\n", Encoding.GetEncoding("EUC-KR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chAutoSelect.Checked == true)
|
||||||
|
{
|
||||||
|
lvList.Items[lvList.Items.Count - 1].Selected = true;
|
||||||
|
lvList.Select();
|
||||||
|
lvList.SelectedItems[0].EnsureVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ColumnHeader col in lvList.Columns)
|
||||||
|
col.Width = -2;
|
||||||
|
|
||||||
|
m_iLastItemCnt = m_ItemList.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lvList_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (lvList.SelectedItems.Count <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string strURL = lvList.SelectedItems[0].SubItems[chLink.Index].Text;
|
||||||
|
wbView.ScriptErrorsSuppressed = true;
|
||||||
|
wbView.Navigate(strURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tbInterval_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
|
{
|
||||||
|
if(e.KeyChar == Convert.ToChar(Keys.Enter))
|
||||||
|
{
|
||||||
|
m_iCrawlInterval = (int)(float.Parse(Regex.Replace(tbInterval.Text, @"\D\.", "")) * 1000);
|
||||||
|
if (m_iCrawlInterval < 1)
|
||||||
|
m_iCrawlInterval = 500;
|
||||||
|
|
||||||
|
tbInterval.Text = (m_iCrawlInterval / (float)1000).ToString("##0.0") + "초";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user