コード例 #1
0
        /// <summary>
        /// Get company infomation from page: companysummary.do
        /// </summary>
        /// <param name="attribute">onclick attribute of node</param>
        /// <returns>company infomation</returns>
        public static KoreaCompany GetCompanyInfoBak(string attribute)
        {
            KoreaCompany company = null;

            try
            {
                //http://kind.krx.co.kr/common/companysummary.do?method=searchCompanySummary&strIsurCd=00347&lstCd=undefined
                string       url = string.Format("http://kind.krx.co.kr/common/companysummary.do?method=searchCompanySummary&strIsurCd={0}&lstCd=undefined", attribute);
                HtmlDocument doc = WebClientUtil.GetHtmlDocument(url, 300000, null);

                if (doc != null)
                {
                    company = new KoreaCompany();
                    HtmlNode table     = doc.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[2]/td[2]").InnerText.Trim();
                    market = GetMarketCode(market);
                    string listingDate = table.SelectSingleNode(".//tr[3]/td[2]").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);
        }
コード例 #2
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);
        }