My Computer Programs

(C#) get web page, KOSPI200 시세 얻기

steloflute 2012. 10. 22. 21:16

.Net Framework 필요

http://msdn.microsoft.com/en-us/netframework/aa569263.aspx

 

 

 

Executable:

 

 

ShowIndex.exe

 

 

Source:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace ShowIndex
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new WebClient();
            var count = 0;
            while (true)
            {
                try
                {
                    var now = DateTime.Now;
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.Write(DateTime.Now.ToString("HH:mm:ss "));
                    Console.ResetColor();
                    new Thread(() =>
                    {
                        string text = client.DownloadString("http://kosdb.koscom.co.kr/main/jisuticker.html");
                        var m = Regex.Match(text, "KOSPI200.*>(.*)&nbsp;&nbsp;(.*)&nbsp;(.*)</font>");
                        Console.Write("{0} {1}{2}  ", m.Groups[1], m.Groups[2], m.Groups[3]);
                        count++;
                        if (count % 3 == 0) Console.WriteLine();
                    }).Start();
                    while (now.Hour <= 8 || now.Hour >= 16 || (now.Hour == 15 && now.Minute > 3))
                    {
                        Thread.Sleep(60 * 1000);
                        now = DateTime.Now;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
                Thread.Sleep(20 * 1000);
            }
        }
    }
}

'My Computer Programs' 카테고리의 다른 글

(newLISP) SweepSecond  (0) 2012.11.05
(Windows, C#) SweepSecond  (0) 2012.10.30
(Windows) show-ip.bat  (0) 2012.10.18
(Racket) processor-count  (0) 2012.10.18
(Racket) permute  (0) 2012.10.05