Ejemplo n.º 1
0
        /// <summary>
        /// Grab drop anouncement from kind webpage.
        /// </summary>
        private void GrabDataFromKindWebpage()
        {
            string startDate = configObj.StartDate;
            string endDate   = configObj.EndDate;

            if (string.IsNullOrEmpty(startDate))
            {
                startDate = DateTime.Today.ToString("yyyy-MM-dd");
            }
            if (string.IsNullOrEmpty(endDate))
            {
                endDate = DateTime.Today.ToString("yyyy-MM-dd");
            }
            string dataStartDate = (DateTime.Parse(endDate).AddMonths(-2)).ToString("yyyy-MM-dd");
            string postData      = string.Format("method=searchTotalInfoSub&forward=searchtotalinfo_detail&searchCodeType=&searchCorpName=%EC%83%81%EC%9E%A5%ED%8F%90%EC%A7%80&repIsuSrtCd=&isurCd=&fdName=all_mktact_idx&pageIndex=1&currentPageSize=300&scn=mktact&srchFd=2&kwd=%EC%83%81%EC%9E%A5%ED%8F%90%EC%A7%80&fromData={0}&toData={1}", dataStartDate, endDate);
            string searchUri     = "http://kind.krx.co.kr/disclosure/searchtotalinfo.do";

            try
            {
                HtmlDocument htc        = new HtmlDocument();
                var          pageSource = WebClientUtil.GetDynamicPageSource(searchUri, 300000, postData);
                if (!string.IsNullOrEmpty(pageSource))
                {
                    htc.LoadHtml(pageSource);
                }
                HtmlNodeCollection nodeCollections = htc.DocumentNode.SelectNodes("//dt");
                HtmlNodeCollection ddCollections   = htc.DocumentNode.SelectNodes("//dl/dd");

                if (nodeCollections.Count > 0)
                {
                    for (int i = nodeCollections.Count - 1; i >= 0; i--)
                    {
                        HtmlNode ddNode = ddCollections[i].SelectSingleNode(".//span");

                        HtmlNode dtNode    = nodeCollections[i];
                        HtmlNode node      = nodeCollections[i].SelectSingleNode(".//span/a");
                        string   titleNode = string.Empty;
                        if (node != null)
                        {
                            titleNode = node.InnerText.ToString();
                        }
                        titleNode = titleNode.Contains("[") ? titleNode.Replace("[", "").Replace("]", "").Trim().ToString() : titleNode;

                        if (titleNode.Contains("신주인수권증권 상장폐지"))
                        {
                            HtmlNode nodeDate = dtNode.SelectSingleNode("./em");
                            if (nodeDate != null)
                            {
                                DateTime anouncementDate = new DateTime();
                                anouncementDate = DateTime.Parse(nodeDate.InnerText.Trim(), new CultureInfo("en-US"));
                                if (anouncementDate < DateTime.Parse(startDate))
                                {
                                    continue;
                                }
                            }
                            string title = titleNode.Substring(0, "신주인수권증권 상장폐지".Length).Trim().ToString();
                            if (title.Equals("신주인수권증권 상장폐지"))
                            {
                                CompanyWarrantDropTemplate item = new CompanyWarrantDropTemplate();
                                HtmlNode header    = nodeCollections[i].SelectSingleNode(".//strong/a");
                                string   attribute = string.Empty;
                                if (header != null)
                                {
                                    attribute = header.Attributes["onclick"].Value.ToString().Trim();
                                }
                                if (!string.IsNullOrEmpty(attribute))
                                {
                                    attribute = attribute.Split('(')[1].Split(')')[0].Trim(new Char[] { ' ', '\'', ';' }).ToString();
                                }

                                string judge = ddNode.InnerText.Split(':')[1].Trim();

                                //string attrituteUri = string.Format("http://kind.krx.co.kr/common/companysummary.do?method=searchCompanySummary&strIsurCd={0}&lstCd=undefined", attribute);
                                //string judge = string.Empty;
                                //HtmlDocument doc = WebClientUtil.GetHtmlDocument(attrituteUri, 120000, null);
                                //if (doc != null)
                                //{
                                //    HtmlNode docnode = doc.DocumentNode.SelectSingleNode("//div[@id='pContents']/table/tbody/tr[2]/td[2]");
                                //    if (docnode != null)
                                //    {
                                //        judge = docnode.InnerText;
                                //    }
                                //}


                                string parameters = node.Attributes["onclick"].Value.ToString().Trim();
                                parameters = parameters.Split('(')[1].Split(')')[0].ToString().Trim(new char[] { ' ', '\'', ';' });
                                string param1 = parameters.Split(',')[0].Trim(new char[] { ' ', '\'', ',' }).ToString();
                                string param2 = parameters.Split(',')[1].Trim(new char[] { ' ', '\'', ',' }).ToString();
                                string uri    = string.Format("http://kind.krx.co.kr/common/disclsviewer.do?method=search&acptno={0}&docno={1}&viewerhost=&viewerport=", param1, param2);

                                HtmlDocument doc    = WebClientUtil.GetHtmlDocument(uri, 300000, null);
                                string       ticker = string.Empty;
                                if (doc != null)
                                {
                                    ticker = doc.DocumentNode.SelectSingleNode("//header/h1").InnerText;
                                }

                                if (!string.IsNullOrEmpty(ticker))
                                {
                                    Match m = Regex.Match(ticker, @"\(([0-9a-zA-Z]{6})\)");
                                    if (m == null)
                                    {
                                        string msg = "Cannot get ticker numbers in ." + ticker;
                                        Logger.Log(msg, Logger.LogType.Error);
                                        continue;
                                    }
                                    ticker = m.Groups[1].Value;
                                }

                                //if (!string.IsNullOrEmpty(ticker))
                                //    ticker = ticker.Split('(')[1].Trim(new char[] { ' ', ')', '(' }).ToString();

                                string param3 = judge.Contains("유가증권") ? "68913" : (judge.Contains("코스닥") ? "70925" : null);
                                if (string.IsNullOrEmpty(param3))
                                {
                                    return;
                                }
                                param1 = param1.Insert(4, "/").Insert(7, "/").Insert(10, "/").ToString();
                                uri    = string.Format("http://kind.krx.co.kr/external/{0}/{1}/{2}.htm", param1, param2, param3);

                                doc = WebClientUtil.GetHtmlDocument(uri, 300000, null);
                                if (doc == null)
                                {
                                    return;
                                }
                                // For KQ
                                if (judge.Contains("코스닥"))
                                {
                                    HtmlNode koreaName = doc.DocumentNode.SelectSingleNode("//tr[1]/td[2]");
                                    HtmlNode effective = doc.DocumentNode.SelectSingleNode("//tr[5]/td[2]");
                                    string   kname     = string.Empty;
                                    string   edate     = string.Empty;
                                    if (koreaName != null)
                                    {
                                        kname = koreaName.InnerText.Trim().ToString();
                                    }
                                    if (effective != null)
                                    {
                                        edate = effective.InnerText.Trim().ToString();
                                    }
                                    kname = kname.Trim().ToString();
                                    if (!string.IsNullOrEmpty(kname))
                                    {
                                        kname = kname.Contains("(주)") ? kname.Replace("(주)", "").Trim() : kname;
                                    }
                                    edate = edate.Trim().ToString();
                                    if (!string.IsNullOrEmpty(edate))
                                    {
                                        edate = Convert.ToDateTime(edate).ToString("yyyy-MMM-dd", new CultureInfo("en-US"));
                                    }
                                    item.KoreanName    = kname;
                                    item.EffectiveDate = edate;
                                    item.RIC           = ticker + ".KQ";
                                    waDrop.Add(item);
                                }
                                //For KS
                                else if (judge.Contains("유가증권"))
                                {
                                    string skName = MiscUtil.GetCleanTextFromHtml(doc.DocumentNode.SelectSingleNode("//tr[1]/td[2]").InnerText);
                                    skName = Regex.Split(skName, "   ", RegexOptions.IgnoreCase)[0].Trim(new char[] { ' ', ':' }).ToString();
                                    string seDate = MiscUtil.GetCleanTextFromHtml(doc.DocumentNode.SelectSingleNode("//tr[8]/td[2]").InnerText);
                                    seDate             = Convert.ToDateTime(seDate).ToString("yyyy-MMM-dd", new CultureInfo("en-US"));
                                    item.KoreanName    = skName;
                                    item.EffectiveDate = seDate;
                                    item.RIC           = ticker + ".KS";
                                    waDrop.Add(item);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                String msg = "Error found in SearchTheWebpageToGrabData()      : \r\n" + ex.InnerException + "  :  \r\n" + ex.ToString();
                Logger.Log(msg, Logger.LogType.Error);
                return;
            }
        }
Ejemplo n.º 2
0
        private void GrabOrgSourceDataFromWebpage()
        {
            try
            {
                string startDate = configObj.StartDate;
                string endDate   = configObj.EndDate;
                string uri       = "http://kind.krx.co.kr/disclosure/disclosurebystocktype.do";
                //string postData = string.Format("method=searchDisclosureByStockTypeSub&currentPageSize=15&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData={0}&toData={1}&reportNm=&elwRsnClss=0914&elwRsnClss=0912&elwRsnClss=0915&elwRsnClss=0910", startDate, endDate);

                string postData = String.Format("method=searchDisclosureByStockTypeElwSub&currentPageSize=15&pageIndex={0}&orderMode=1&orderStat=D&forward=disclosurebystocktype_elw_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&fromDate={1}&toDate={2}&reportNm=%EC%83%81%EC%9E%A5%ED%8F%90%EC%A7%80", 0, startDate, endDate);

                string pageSource = WebClientUtil.GetDynamicPageSource(uri, 180000, postData);
                HtmlAgilityPack.HtmlDocument htc = new HtmlAgilityPack.HtmlDocument();
                if (!string.IsNullOrEmpty(pageSource))
                {
                    htc.LoadHtml(pageSource);
                }
                if (htc != null)
                {
                    HtmlNode           tbodyNode       = htc.DocumentNode.SelectNodes("//table")[0].SelectSingleNode(".//tbody");
                    HtmlNodeCollection nodeCollections = tbodyNode.SelectNodes(".//tr");
                    int count = nodeCollections.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var      item      = nodeCollections[i] as HtmlNode;
                        HtmlNode titleNode = item.SelectSingleNode(".//td[4]/a");
                        if (titleNode == null)
                        {
                            continue;
                        }
                        string title = titleNode.InnerText.Trim().ToString();
                        if (!string.IsNullOrEmpty(title) && title.Equals("주식워런트증권 상장폐지조치"))
                        {
                            string companyname = item.SelectSingleNode(".//td[3]").InnerText;
                            string attribute   = string.Empty;
                            attribute = item.SelectSingleNode(".//td[4]/a").Attributes["onclick"].Value.Trim().ToString();
                            attribute = attribute.Split('(')[1].Split(',')[0].Trim(new char[] { ' ', '\'', ',' }).ToString();
                            string url = string.Format("http://kind.krx.co.kr/common/disclsviewer.do?method=search&acptno={0}&docno=&viewerhost=&viewerport=", attribute);
                            System.Threading.Thread.Sleep(2000);
                            string source = WebClientUtil.GetDynamicPageSource(url, 300000, null);
                            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                            if (!string.IsNullOrEmpty(source))
                            {
                                doc.LoadHtml(source);
                            }
                            if (doc != null)
                            {
                                //string parameter = doc.DocumentNode.SelectSingleNode(".//div/select[@id='mainDocId']/option[2]").Attributes["value"].Value.Trim().ToString();
                                String parameter = doc.DocumentNode.SelectSingleNode(".//select[@id='mainDoc']/option[2]").Attributes["value"].Value.Trim().ToString();
                                parameter = parameter.Trim().ToString().Replace("|Y", "");

                                attribute = attribute.Insert(4, "/").Insert(7, "/").Insert(10, "/").Trim().ToString();
                                url       = String.Format("http://kind.krx.co.kr/external/{0}/{1}/68955.htm", attribute, parameter);
                                doc       = WebClientUtil.GetHtmlDocument(url, 300000, null);
                                if (doc != null)
                                {
                                    string str_pre = doc.DocumentNode.SelectSingleNode(".//pre").InnerText.Trim().ToString();
                                    str_pre = str_pre.Trim().ToString();

                                    int str_judge_start_pos = str_pre.IndexOf("상장폐지사유") + "상장폐지사유".Length;

                                    string str_judge = FormatDataWithPos(str_judge_start_pos, str_pre);

                                    if (str_judge != "최종거래일 도래")
                                    {
                                        int    str_effective_date_start_pos = str_pre.IndexOf("상장폐지일") + "상장폐지일".Length;
                                        string str_effective_date           = FormatDataWithPos(str_effective_date_start_pos, str_pre);

                                        int    str_company_start_pos = str_pre.IndexOf("상장폐지 주식워런트증권 종목명") + "상장폐지 주식워런트증권 종목명".Length; //33
                                        string preLeft = str_pre.Substring(str_company_start_pos);

                                        int    indexNum    = 1;
                                        string indexSuffix = ".";
                                        string pattern     = @"\n.*?(?<IndexNum>\d).*?상장폐지 주식워런트증권 종목명";
                                        Regex  regex       = new Regex(pattern);
                                        Match  match       = regex.Match(str_pre);
                                        if (match.Success)
                                        {
                                            indexNum    = Convert.ToInt16(match.Groups["IndexNum"].Value);
                                            indexSuffix = match.Value.Replace("상장폐지 주식워런트증권 종목명", "").Replace(indexNum.ToString(), "").Trim(' ', '\n');
                                        }
                                        string nextIndex        = (indexNum + 1).ToString() + indexSuffix;
                                        int    strCompanyEndPos = preLeft.IndexOf(nextIndex);
                                        string str_company_arr  = str_pre.Substring(str_company_start_pos, strCompanyEndPos).Trim('\n', '\r', '\t', ' ');

                                        string[] company_arr = str_company_arr.TrimStart(new char[] { '-', ' ', '▶' }).Split('\n');

                                        for (var x = 0; x < company_arr.Length; x++)
                                        {
                                            ELWFMDropModel ELWDrop = new ELWFMDropModel();
                                            ELWDrop.OrgSource     = company_arr[x].Trim(new Char[] { '-', ' ', '▶' }).ToString();
                                            ELWDrop.EffectiveDate = str_effective_date.Trim().ToString();
                                            ELWDrop.UpdateDate    = ELWDrop.EffectiveDate;
                                            ELWDrop.Publisher     = companyname;
                                            dropList.Add(ELWDrop);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "Error found in GrabOrgSourceDataFromWebpage()     : \r\n" + ex.ToString();
                Logger.Log(msg, Logger.LogType.Error);
            }
        }
Ejemplo n.º 3
0
        private void GrabDataFromWebpage()
        {
            String startDate = configObj.Korea_SPCRAdjustment_StartDate.Trim().ToString();
            String endDate   = configObj.Korea_SPCRAdjustment_EndDate.Trim().ToString();
            //method=searchDisclosureByStockTypeSub&currentPageSize=15&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData=2011-06-01&toData=2011-12-01&reportNm=&elwRsnClss=09003
            //method=searchDisclosureByStockTypeSub&currentPageSize=100&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData=2011-06-01&toData=2011-12-01&reportNm=&elwRsnClss=09003
            //method=searchDisclosureByStockTypeSub&currentPageSize=100&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData=2011-06-02&toData=2011-12-02&reportNm=&elwRsnClss=09003
            String            postData   = String.Format("method=searchDisclosureByStockTypeSub&currentPageSize=300&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData={0}&toData={1}&reportNm=&elwRsnClss=09003", startDate, endDate);
            String            uri        = "http://kind.krx.co.kr/disclosure/disclosurebystocktype.do";
            AdvancedWebClient wc         = new AdvancedWebClient();
            String            pageSource = String.Empty;

            pageSource = WebClientUtil.GetDynamicPageSource(uri, 300000, postData);
            //pageSource = WebClientUtil.GetPageSource(wc, uri, 300000, postData);
            HtmlDocument htc = new HtmlDocument();

            if (!String.IsNullOrEmpty(pageSource))
            {
                htc.LoadHtml(pageSource);
            }
            if (htc != null)
            {
                HtmlNodeCollection nodeCollections = htc.DocumentNode.SelectNodes(".//div[@id='menu1']/table/tbody/tr");
                int count = nodeCollections.Count;
                if (count > 0)
                {
                    for (var i = 0; i < count; i++)
                    {
                        HtmlNode node      = nodeCollections[i].SelectSingleNode(".//td[4]/a");
                        String   attribute = String.Empty;
                        if (node != null)
                        {
                            attribute = node.Attributes["onclick"].Value.Trim().ToString();
                        }
                        if (!String.IsNullOrEmpty(attribute))
                        {
                            attribute = attribute.Split('(')[1].Split(',')[0].Trim(new Char[] { ' ', '\'' }).ToString();
                            //http://kind.krx.co.kr/common/disclsviewer.do?method=search&acptno=20111201000283&docno=&viewerhost=&viewerport=
                            uri = String.Format("http://kind.krx.co.kr/common/disclsviewer.do?method=search&acptno={0}&docno=&viewerhost=&viewerport=", attribute /*"20111201000283"*/);
                            HtmlDocument doc = new HtmlDocument();
                            pageSource = WebClientUtil.GetDynamicPageSource(uri, 300000, null);
                            if (!String.IsNullOrEmpty(pageSource))
                            {
                                doc.LoadHtml(pageSource);
                            }
                            String parameter = String.Empty;
                            if (doc != null)
                            {
                                //doc.DocumentNode.SelectSingleNode(".//div[@id='pWrapper']/div[@id='pContArea']/form[@name='frm']/select[@id='mainDocId']/option[2]")
                                parameter = doc.DocumentNode.SelectSingleNode(".//select[@id='mainDocId']/option[2]").Attributes["value"].Value.Trim().ToString();
                            }

                            attribute = attribute.Insert(4, "/").Insert(7, "/").Insert(10, "/");
                            //http://kind.krx.co.kr/external/2011/12/01/000283/20111201000641/99858.htm
                            uri = String.Format("http://kind.krx.co.kr/external/{0}/{1}/99858.htm", attribute, parameter);
                            doc = null;
                            doc = WebClientUtil.GetHtmlDocument(uri, 300000, null);
                            if (doc != null)
                            {
                                String judgeStr = doc.DocumentNode.SelectSingleNode("//table[@id='XFormD1_Form0_RepeatTable0']/tbody/tr[1]/td[2]/span").InnerText;
                                if (!String.IsNullOrEmpty(judgeStr))
                                {
                                    if (!judgeStr.Equals("확정"))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        HtmlNodeCollection trNodes = doc.DocumentNode.SelectNodes("//tr");
                                        int      amount            = trNodes.Count;
                                        HtmlNode eNode             = trNodes[(amount - 1)];
                                        String   edate             = String.Empty;
                                        if (eNode != null)
                                        {
                                            edate = eNode.SelectSingleNode(".//td[2]").InnerText.Trim().ToString().Replace(" ", "");
                                            int pos = edate.IndexOf("부터");
                                            edate = edate.Substring((pos - 11), 11);
                                            Char[] arr = edate.ToCharArray();
                                            if (arr[0] < 47 && arr[0] > 58)
                                            {
                                                edate = edate.Substring(1);
                                                arr   = edate.ToCharArray();
                                                if (arr[0] < 47 && arr[0] > 58)
                                                {
                                                    edate = edate.Substring(1);
                                                }
                                            }

                                            edate = Convert.ToDateTime(edate).ToString("yyyy-MMM-dd", new CultureInfo("en-US")).ToUpper();
                                        }

                                        for (var x = 6; x < (amount - 3); x++)
                                        {
                                            SPCRAdjustmentTemplate spcr = new SPCRAdjustmentTemplate();
                                            HtmlNode itemNode           = trNodes[x];
                                            if (itemNode != null)
                                            {
                                                String isin   = itemNode.SelectSingleNode(".//td[1]").InnerText.Trim().ToString();
                                                String kname  = itemNode.SelectSingleNode(".//td[2]").InnerText.Trim().ToString();
                                                String sprice = itemNode.SelectSingleNode(".//td[7]").InnerText.Trim().ToString();
                                                sprice = sprice.Contains(",") ? sprice.Replace(",", "") : sprice;
                                                String cratio = itemNode.SelectSingleNode(".//td[9]").InnerText.Trim().ToString();
                                                spcr.EffectiveDate   = edate;
                                                spcr.ISIN            = isin;
                                                spcr.KoreaName       = kname;
                                                spcr.StrikePrice     = sprice;
                                                spcr.ConversionRatio = cratio;
                                                spcrList.Add(spcr);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static KoreaCompany GetCompanyInfo(string attribute)
        {
            KoreaCompany company = null;

            try
            {
                string uri             = "http://kind.krx.co.kr/common/companysummary.do";
                string companyPostData = string.Format("method=searchCompanySummaryOvrvwDetail&menuIndex=0&strIsurCd={0}&lstCd=undefined&taskDd=&spotIsuTrdMktTpCd=&methodType=0", attribute);

                string companyPageSource = null;
                int    retry             = 3;

                while (string.IsNullOrEmpty(companyPageSource) && retry-- > 0)
                {
                    try
                    {
                        companyPageSource = WebClientUtil.GetDynamicPageSource(uri, 300000, companyPostData);
                    }
                    catch
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }

                if (string.IsNullOrEmpty(companyPageSource))
                {
                    return(null);
                }

                companyPageSource = MiscUtil.GetCleanTextFromHtml(companyPageSource);
                HtmlDocument companyDoc = new HtmlDocument();
                if (!string.IsNullOrEmpty(companyPageSource))
                {
                    companyDoc.LoadHtml(companyPageSource);
                }


                if (companyDoc != null)
                {
                    company = new KoreaCompany();
                    HtmlNode table     = companyDoc.DocumentNode.SelectNodes("//table")[0];
                    string   koreaName = table.SelectSingleNode(".//tr[1]/td[1]").InnerText.Trim();
                    string   legalName = table.SelectSingleNode(".//tr[1]/td[2]").InnerText.Trim();
                    string   isin      = table.SelectSingleNode(".//tr[2]/td[1]").InnerText.Trim();;
                    string   market    = table.SelectSingleNode(".//tr[3]/td[2]").InnerText.Trim();
                    market = GetMarketCode(market);
                    string listingDate = table.SelectSingleNode(".//tr[3]/td[1]").InnerText.Trim();

                    if (!string.IsNullOrEmpty(market))
                    {
                        company.Market = market;
                    }
                    if (!string.IsNullOrEmpty(isin))
                    {
                        company.ISIN = isin;
                    }
                    if (!string.IsNullOrEmpty(legalName))
                    {
                        company.LegalName = legalName;
                    }
                    if (!string.IsNullOrEmpty(koreaName))
                    {
                        company.KoreaName = koreaName;
                    }
                    if (!string.IsNullOrEmpty(listingDate))
                    {
                        company.ListingDate = listingDate;
                    }
                }
            }
            catch
            {
                return(null);
            }
            return(company);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Search the ISIN website for given korean name and key word: 보통주 first time: search with koreanName + 보통주. second time: search with koreanName
        /// If mutiple records or no record found. User need to input ISIN.
        /// </summary>
        /// <param name="koreanName">korean name</param>
        /// <param name="times">searched times</param>
        /// <returns>isin</returns>
        public static string GetIsinByName(string koreanName, int times)
        {
            string postData   = "";
            string encodeName = Encode(koreanName);

            if (koreanName.Contains("-"))
            {
                encodeName = Encode(koreanName.Split('-')[1]);
            }

            if (times == 0)
            {
                postData = string.Format("kind=&ef_std_cd_grnt_dt_from=&ef_std_cd_grnt_dt_to=&secuGubun=01&lst_yn1=Y&els_dls_all=on&els_dls1=els&els_dls2=dls&so_gb_all=on&so_gb1=s&so_gb2=o&jp_gb_all=on&jp_gb1=c&jp_gb2=t&jp_gb3=r&jp_gb4=i&hg_gb_all=on&hg_gb1=h&hg_gb2=g&tg_gb_all=on&tg_gb1=x&tg_gb2=z&df_gb_all=on&df_gb1=df1&df_gb2=df2&df_gb3=df3&df_gb4=df4&df_gb5=df5&df_gb6=df6&df_gb7=df7&cb_search_column=co_nm&ef_key_word={0}&ef_iss_inst_cd=&ef_isu_nm={0}%BA%B8%C5%EB%C1%D6&ef_iss_dt_from=&ef_iss_dt_to=&ef_lst_dt_from=&ef_lst_dt_to=", encodeName);
            }
            else if (times == 1)
            {
                postData = string.Format("kind=&ef_std_cd_grnt_dt_from=&ef_std_cd_grnt_dt_to=&secuGubun=01&lst_yn1=Y&els_dls_all=on&els_dls1=els&els_dls2=dls&so_gb_all=on&so_gb1=s&so_gb2=o&jp_gb_all=on&jp_gb1=c&jp_gb2=t&jp_gb3=r&jp_gb4=i&hg_gb_all=on&hg_gb1=h&hg_gb2=g&tg_gb_all=on&tg_gb1=x&tg_gb2=z&df_gb_all=on&df_gb1=df1&df_gb2=df2&df_gb3=df3&df_gb4=df4&df_gb5=df5&df_gb6=df6&df_gb7=df7&cb_search_column=co_nm&ef_key_word={0}&ef_iss_inst_cd=&ef_isu_nm=%BA%B8%C5%EB%C1%D6&ef_iss_dt_from=&ef_iss_dt_to=&ef_lst_dt_from=&ef_lst_dt_to=", encodeName);
            }
            string         uri     = "http://isin.krx.co.kr/jsp/realBoard01.jsp";
            HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;

            request.Timeout     = 100000;
            request.UserAgent   = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2";
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Referer     = "http://isin.krx.co.kr/jsp/BA_LT113.jsp";
            request.Headers.Add("Accept-Encoding: gzip,deflate,sdch");

            string pageSource = null;
            int    retries    = 3;

            while (pageSource == null && retries-- > 0)
            {
                try
                {
                    pageSource = WebClientUtil.GetDynamicPageSource(request, postData, Encoding.GetEncoding("EUC-KR"));
                }
                catch
                {
                    System.Threading.Thread.Sleep(5000);
                }
            }
            string       isin = "";
            HtmlDocument doc  = new HtmlDocument();

            doc.LoadHtml(pageSource);

            HtmlNodeCollection trs = null;

            try
            {
                trs = doc.DocumentNode.SelectNodes("/html[1]/body[1]/table[1]/tr[2]/td[1]/table[1]/tr");
            }
            catch
            {
                string msg = "Error found in searching new underlying record found for " + koreanName;
                //Logger.Log(msg, Logger.LogType.Error);
                isin = InputISIN.Prompt(koreanName, "Underlying Name");
            }
            //not found
            if (trs == null || trs.Count > 2)
            {
                isin = InputISIN.Prompt(koreanName, "Underlying Name");
            }
            else if (trs.Count == 1)
            {
                isin = times == 0 ? GetIsinByName(koreanName, 1) : InputISIN.Prompt(koreanName, "Underlying Name");
            }
            //find only one record
            else if (trs.Count == 2)
            {
                HtmlNode           tr  = trs[1];
                HtmlNodeCollection tds = tr.SelectNodes("./td");
                isin = tds[1].InnerText.Trim();
            }
            return(isin);
        }