private void downloadAndParseIndexFile(string url) { string szseIndexFilePath = targetDownloadFileDir(); szseIndexFilePath += "\\SZSE"; if (!Directory.Exists(szseIndexFilePath)) { Directory.CreateDirectory(szseIndexFilePath); } szseIndexFilePath += "\\Index.xls"; WebClientUtil.DownloadFile(url, 180000, szseIndexFilePath); using (ExcelApp app = new ExcelApp(false, false)) { var workbook = ExcelUtil.CreateOrOpenExcelFile(app, szseIndexFilePath); var worksheet = workbook.Worksheets[1] as Worksheet; int lastUsedRow = worksheet.UsedRange.Row + worksheet.UsedRange.Rows.Count - 1; for (int i = 2; i <= lastUsedRow; i++) { Range aRange = ExcelUtil.GetRange(i, 1, worksheet); if (aRange != null && aRange.Text.ToString().Trim() != string.Empty) { ChinaIndex index = new ChinaIndex(); index.Chain = aRange.Text.ToString().Trim(); index.ChineseName = ExcelUtil.GetRange(i, 2, worksheet).Text.ToString(); szseIndexList.Add(index); } } } }
private void getSSEIndexList() { var doc = WebClientUtil.GetHtmlDocument(string.Format("{0}/sseportal/index/cn/common/index_list_new.shtml", configObj.SseBaseUri), 180000, "", Encoding.GetEncoding("gb2312")); var nodeList = doc.DocumentNode.SelectNodes("//td[@class='table2']//a"); foreach (HtmlNode node in nodeList) { //http://www.sse.com.cn/sseportal/index/cn/i000010/intro. if (node.ParentNode.Attributes["align"] == null) { ChinaIndex index = new ChinaIndex(); index.ChineseName = MiscUtil.GetCleanTextFromHtml(node.InnerText); index.SourceUrl = string.Format("{0}{1}", configObj.SseBaseUri, node.Attributes["href"].Value); //http://www.sse.com.cn/sseportal/index/cn/i000010/intro.shtml //http://www.sse.com.cn/sseportal/index/cn/i000010/const_list.shtml index.SourceUrl = index.SourceUrl.Replace("intro.shtml", "const_list.shtml"); sseIndexList.Add(index); } } updateSSEIndexListWithRic(); }
private void getCSIIndexList() { //string pageSource = WebClientUtil.GetPageSource(null, string.Format("{0}/sseportal/csiportal/xzzx/queryindexdownloadlist.do?type=1", configObj.CSI_BASE_URI), 180000, "", Encoding.GetEncoding("gb2312")); var doc = WebClientUtil.GetHtmlDocument(string.Format("{0}/sseportal/csiportal/xzzx/queryindexdownloadlist.do?type=1", configObj.CsiBaseUri), 180000, "", Encoding.GetEncoding("gb2312")); var nodeList = doc.DocumentNode.SelectNodes("//tr[@align='center']"); var nodeList2 = doc.DocumentNode.SelectNodes("//tr[@class='list-div-table-header']"); foreach (HtmlNode node in nodeList2) { nodeList.Append(node); } for (int i = 0; i < nodeList.Count; i++) { ChinaIndex index = new ChinaIndex(); index.ChineseName = MiscUtil.GetCleanTextFromHtml(nodeList[i].ChildNodes[2 * 0 + 1].ChildNodes[2].InnerText); try { if (nodeList[i].ChildNodes[2 * 5 + 1].ChildNodes.Count == 3) { index.SourceUrl = configObj.CsiBaseUri + MiscUtil.GetCleanTextFromHtml(nodeList[i].ChildNodes[2 * 5 + 1].ChildNodes[1].Attributes["href"].Value); index.OfficeCode = getOfficialCodeForCSI(index.SourceUrl); index.RicList = getRicsForCSI(index.SourceUrl); csiIndexList.Add(index); } else { Logger.Log(string.Format("There's no '成分股列表'in the exchange web site for {0}", index.ChineseName)); } } catch (Exception ex) { Logger.Log(string.Format("There's error when parsing information for {0}. Exception message: {1} ", index.ChineseName, ex.Message)); } } }