static List <struIncreaseStock> GetMultiTarget(HTMLEngine.MyRootHtmlNode root, struIncreaseStock SampleincreaseStock) { var BuyerRule = new TableSearchRule(); BuyerRule.Name = "认购对象"; //"投资者名称","股东名称" BuyerRule.Rule = new string[] { "发行对象", "认购对象", "发行对象名称" }.ToList(); BuyerRule.IsEq = true; var BuyNumber = new TableSearchRule(); BuyNumber.Name = "增发数量"; BuyNumber.Rule = new string[] { "配售股数", "认购数量", "认购股份数" }.ToList(); BuyNumber.IsEq = false; //包含即可 BuyNumber.Normalize = Normalizer.NormalizerStockNumber; var BuyMoney = new TableSearchRule(); BuyMoney.Name = "增发金额"; BuyMoney.Rule = new string[] { "配售金额", "认购金额" }.ToList(); BuyMoney.IsEq = false; //包含即可 BuyMoney.Normalize = Normalizer.NormalizerMoney; var FreezeYear = new TableSearchRule(); FreezeYear.Name = "锁定期"; FreezeYear.Rule = new string[] { "锁定期", "限售期" }.ToList(); FreezeYear.IsEq = false; //包含即可 FreezeYear.Normalize = NormalizerFreezeYear; var Rules = new List <TableSearchRule>(); Rules.Add(BuyerRule); Rules.Add(BuyNumber); Rules.Add(BuyMoney); Rules.Add(FreezeYear); var result = HTMLTable.GetMultiInfo(root, Rules, true); var increaseStocklist = new List <struIncreaseStock>(); foreach (var item in result) { var increase = new struIncreaseStock(); increase.id = SampleincreaseStock.id; increase.BuyMethod = SampleincreaseStock.BuyMethod; increase.PublishTarget = item[0].RawData; if (String.IsNullOrEmpty(increase.PublishTarget)) { continue; } increase.IncreaseNumber = item[1].RawData; increase.IncreaseMoney = item[2].RawData; increase.FreezeYear = item[3].RawData; increaseStocklist.Add(increase); } return(increaseStocklist); }
static List <struStockChange> ExtractFromTable(HTMLEngine.MyRootHtmlNode root, string id) { var StockHolderRule = new TableSearchRule(); StockHolderRule.Name = "股东全称"; StockHolderRule.Rule = new string[] { "股东名称" }.ToList(); StockHolderRule.IsEq = true; var ChangeDateRule = new TableSearchRule(); ChangeDateRule.Name = "变动截止日期"; ChangeDateRule.Rule = new string[] { "减持期间", "增持期间", "减持时间", "增持时间" }.ToList(); ChangeDateRule.IsEq = false; ChangeDateRule.Normalize = Normalizer.NormailizeDate; var ChangePriceRule = new TableSearchRule(); ChangePriceRule.Name = "变动价格"; ChangePriceRule.Rule = new string[] { "减持均价", "增持均价" }.ToList(); ChangePriceRule.IsEq = false; ChangePriceRule.Normalize = (x, y) => { if (x.Contains("元")) { return(Utility.GetStringBefore(x, "元")); } return(x); }; var ChangeNumberRule = new TableSearchRule(); ChangeNumberRule.Name = "变动数量"; ChangeNumberRule.Rule = new string[] { "减持股数", "增持股数" }.ToList(); ChangeNumberRule.IsEq = false; ChangeNumberRule.Normalize = Normalizer.NormalizerStockNumber; var Rules = new List <TableSearchRule>(); Rules.Add(StockHolderRule); Rules.Add(ChangeDateRule); Rules.Add(ChangePriceRule); Rules.Add(ChangeNumberRule); var result = HTMLTable.GetMultiInfo(root, Rules, false); //只写在最后一条记录的地方,不过必须及时过滤掉不存在的记录 result.Reverse(); var stockchangelist = new List <struStockChange>(); foreach (var rec in result) { var stockchange = new struStockChange(); stockchange.id = id; var Name = NormalizeCompanyName(rec[0].RawData); stockchange.HolderFullName = Name.Item1; stockchange.HolderShortName = Name.Item2; stockchange.ChangeEndDate = rec[1].RawData; stockchange.ChangePrice = rec[2].RawData; stockchange.ChangeNumber = rec[3].RawData; var holderafterlist = GetHolderAfter(root); for (int i = 0; i < holderafterlist.Count; i++) { var after = holderafterlist[i]; if (after.Used) { continue; } if (after.Name == stockchange.HolderFullName || after.Name == stockchange.HolderShortName) { stockchange.HoldNumberAfterChange = after.Count; stockchange.HoldPercentAfterChange = after.Percent; after.Used = true; break; } } //基本上所有的有效记录都有股东名和截至日期,所以,这里这么做,可能对于极少数没有截至日期的数据有伤害,但是对于整体指标来说是好的 if (string.IsNullOrEmpty(stockchange.HolderFullName) || string.IsNullOrEmpty(stockchange.ChangeEndDate)) { continue; } stockchangelist.Add(stockchange); } //合并记录 for (int i = 0; i < stockchangelist.Count; i++) { var x = stockchangelist[i]; for (int j = i + 1; j < stockchangelist.Count; j++) { var y = stockchangelist[j]; if (x.GetKey() == y.GetKey()) { if (string.IsNullOrEmpty(x.HoldNumberAfterChange) && !string.IsNullOrEmpty(y.HoldNumberAfterChange)) { x.id = ""; } if (!string.IsNullOrEmpty(x.HoldNumberAfterChange) && string.IsNullOrEmpty(y.HoldNumberAfterChange)) { y.id = ""; } } } } return(stockchangelist.Where((x) => { return !String.IsNullOrEmpty(x.id); }).ToList()); }
List <struHoldAfter> GetHolderAfter3rdStep() { var HoldList = new List <struHoldAfter>(); var StockHolderRule = new TableSearchRule(); StockHolderRule.Name = "股东全称"; StockHolderRule.Title = new string[] { "股东名称", "名称", "增持主体", "增持人", "减持主体", "减持人" }.ToList(); StockHolderRule.IsTitleEq = true; StockHolderRule.IsRequire = true; var HoldNumberAfterChangeRule = new TableSearchRule(); HoldNumberAfterChangeRule.Name = "变动后持股数"; HoldNumberAfterChangeRule.IsRequire = true; HoldNumberAfterChangeRule.SuperTitle = new string[] { "减持后", "增持后" }.ToList(); HoldNumberAfterChangeRule.IsSuperTitleEq = false; HoldNumberAfterChangeRule.Title = new string[] { "持股股数", "持股股数", "持股数量", "持股数量", "持股总数", "持股总数", "股数" }.ToList(); HoldNumberAfterChangeRule.IsTitleEq = false; var HoldPercentAfterChangeRule = new TableSearchRule(); HoldPercentAfterChangeRule.Name = "变动后持股数比例"; HoldPercentAfterChangeRule.IsRequire = true; HoldPercentAfterChangeRule.SuperTitle = HoldNumberAfterChangeRule.SuperTitle; HoldPercentAfterChangeRule.IsSuperTitleEq = false; HoldPercentAfterChangeRule.Title = new string[] { "比例" }.ToList(); HoldPercentAfterChangeRule.IsTitleEq = false; var Rules = new List <TableSearchRule>(); Rules.Add(StockHolderRule); Rules.Add(HoldNumberAfterChangeRule); Rules.Add(HoldPercentAfterChangeRule); var result = HTMLTable.GetMultiInfo(root, Rules, false); if (result.Count != 0) { foreach (var item in result) { var HolderName = item[0].RawData; var strHolderCnt = item[1].RawData; strHolderCnt = Normalizer.NormalizeNumberResult(strHolderCnt); string HolderCnt = getAfterstock(item[1].Title, strHolderCnt); var StrPercent = item[2].RawData; var HodlerPercent = getAfterpercent(StrPercent); //Console.WriteLine("GetHolderAfter3rdStep:" + HolderName); HoldList.Add(new struHoldAfter() { Name = HolderName, Count = HolderCnt, Percent = HodlerPercent, Used = false }); } } else { StockHolderRule.SuperTitle = StockHolderRule.Title; StockHolderRule.IsSuperTitleEq = true; StockHolderRule.Title = null; StockHolderRule.IsTitleEq = false; Rules = new List <TableSearchRule>(); Rules.Add(HoldNumberAfterChangeRule); Rules.Add(HoldPercentAfterChangeRule); Rules.Add(StockHolderRule); result = HTMLTable.GetMultiInfo(root, Rules, false); if (result.Count != 0) { foreach (var item in result) { var HolderName = item[2].RawData; var strHolderCnt = item[0].RawData; strHolderCnt = Normalizer.NormalizeNumberResult(strHolderCnt); string HolderCnt = getAfterstock(item[1].Title, strHolderCnt); var StrPercent = item[1].RawData; var HodlerPercent = getAfterpercent(StrPercent); //Console.WriteLine("GetHolderAfter4thStep:" + HolderName); HoldList.Add(new struHoldAfter() { Name = HolderName, Count = HolderCnt, Percent = HodlerPercent, Used = false }); } } } return(HoldList); }
List <struStockChange> ExtractFromTable(HTMLEngine.MyRootHtmlNode root, string id) { var StockHolderRule = new TableSearchRule(); StockHolderRule.Name = "股东全称"; StockHolderRule.Title = new string[] { "股东名称", "名称", "增持主体", "增持人", "减持主体", "减持人" }.ToList(); StockHolderRule.IsTitleEq = true; StockHolderRule.IsRequire = true; var ChangeDateRule = new TableSearchRule(); ChangeDateRule.Name = "变动截止日期"; ChangeDateRule.Title = new string[] { "买卖时间", "日期", "减持期间", "增持期间", "减持股份期间", "增持股份期间", "减持时间", "增持时间", "减持股份时间", "增持股份时间" }.ToList(); ChangeDateRule.IsTitleEq = false; ChangeDateRule.Normalize = NormailizeEndChangeDate; var ChangePriceRule = new TableSearchRule(); ChangePriceRule.Name = "变动价格"; ChangePriceRule.Title = new string[] { "成交均价", "减持价格", "增持价格", "减持均", "增持均" }.ToList(); ChangePriceRule.IsTitleEq = false; ChangePriceRule.Normalize = (x, y) => { if (x.Contains("元")) { return(Utility.GetStringBefore(x, "元")); } return(x); }; var ChangeNumberRule = new TableSearchRule(); ChangeNumberRule.Name = "变动数量"; ChangeNumberRule.Title = new string[] { "成交数量", "减持股数", "增持股数", "减持数量", "增持数量" }.ToList(); ChangeNumberRule.IsTitleEq = false; ChangeNumberRule.Normalize = NumberUtility.NormalizerStockNumber; var Rules = new List <TableSearchRule>(); Rules.Add(StockHolderRule); Rules.Add(ChangeDateRule); Rules.Add(ChangePriceRule); Rules.Add(ChangeNumberRule); var result = HTMLTable.GetMultiInfo(root, Rules, false); if (result.Count == 0) { //没有抽取到任何数据 Rules.Clear(); ChangeDateRule.IsRequire = true; Rules.Add(ChangeDateRule); Rules.Add(ChangePriceRule); Rules.Add(ChangeNumberRule); result = HTMLTable.GetMultiInfo(root, Rules, false); if (result.Count == 0) { return(new List <struStockChange>()); } var NewResult = new List <CellInfo[]>(); var Name = GetHolderName(this.root); if (String.IsNullOrEmpty(Name.FullName) && String.IsNullOrEmpty(Name.ShortName)) { return(new List <struStockChange>()); } foreach (var item in result) { NewResult.Add(new CellInfo[] { new CellInfo() { RawData = String.IsNullOrEmpty(Name.FullName)?Name.ShortName:Name.FullName }, item[0], item[1], item[2] }); } result = NewResult; } var holderafterlist = GetHolderAfter(); var stockchangelist = new List <struStockChange>(); foreach (var rec in result) { var stockchange = new struStockChange(); stockchange.id = id; var ModifyName = rec[0].RawData; //表格里面长的名字可能被分页切割掉 //这里使用合计表进行验证 if (!holderafterlist.Select((z) => { return(z.Name); }).ToList().Contains(ModifyName)) { foreach (var item in holderafterlist) { if (item.Name.EndsWith("先生")) { break; //特殊处理,没有逻辑可言 } if (item.Name.StartsWith(ModifyName) && !item.Name.Equals(ModifyName)) { ModifyName = item.Name; break; } if (item.Name.EndsWith(ModifyName) && !item.Name.Equals(ModifyName)) { ModifyName = item.Name; break; } } } var Name = CompanyNameLogic.NormalizeCompanyName(this, ModifyName); stockchange.HolderFullName = Name.FullName.NormalizeTextResult(); stockchange.HolderShortName = Name.ShortName; if (stockchange.HolderFullName.Contains("简称")) { stockchange.HolderShortName = Utility.GetStringAfter(stockchange.HolderFullName, "简称"); stockchange.HolderShortName = stockchange.HolderShortName.Replace(")", String.Empty).Replace("“", String.Empty).Replace("”", String.Empty); stockchange.HolderFullName = Utility.GetStringBefore(stockchange.HolderFullName, "("); } stockchange.ChangeEndDate = rec[1].RawData; DateTime x; if (!DateTime.TryParse(stockchange.ChangeEndDate, out x)) { //无法处理的情况 if (!Program.IsDebugMode) { //非调试模式 stockchange.ChangeEndDate = String.Empty; } } if (!String.IsNullOrEmpty(rec[2].RawData)) { //股价区间化的去除 if (!(rec[2].RawData.Contains("-") || rec[2].RawData.Contains("~") || rec[2].RawData.Contains("至"))) { stockchange.ChangePrice = rec[2].RawData.Replace(" ", String.Empty); stockchange.ChangePrice = stockchange.ChangePrice.NormalizeNumberResult(); } } if (!RegularTool.IsUnsign(stockchange.ChangePrice)) { if (!String.IsNullOrEmpty(stockchange.ChangePrice)) { Console.WriteLine("Error ChangePrice:[" + stockchange.ChangePrice + "]"); } stockchange.ChangePrice = String.Empty; } if (!String.IsNullOrEmpty(rec[3].RawData)) { stockchange.ChangeNumber = rec[3].RawData.Replace(" ", String.Empty); stockchange.ChangeNumber = stockchange.ChangeNumber.NormalizeNumberResult(); if (!RegularTool.IsUnsign(stockchange.ChangeNumber)) { if (!String.IsNullOrEmpty(stockchange.ChangeNumber)) { Console.WriteLine("Error ChangeNumber:[" + stockchange.ChangeNumber + "]"); } stockchange.ChangeNumber = String.Empty; } } //基本上所有的有效记录都有股东名和截至日期,所以,这里这么做,可能对于极少数没有截至日期的数据有伤害,但是对于整体指标来说是好的 if (string.IsNullOrEmpty(stockchange.HolderFullName) || string.IsNullOrEmpty(stockchange.ChangeEndDate)) { continue; } if (stockchange.ChangeNumber == "0" || stockchange.ChangePrice == "0") { continue; } stockchangelist.Add(stockchange); } //寻找所有的股东全称 var namelist = stockchangelist.Select(x => x.HolderFullName).Distinct().ToList(); var newRec = new List <struStockChange>(); foreach (var name in namelist) { var stocklist = stockchangelist.Where((x) => { return(x.HolderFullName == name); }).ToList(); stocklist.Sort((x, y) => { return(x.ChangeEndDate.CompareTo(y.ChangeEndDate)); }); var last = stocklist.Last(); for (int i = 0; i < holderafterlist.Count; i++) { var after = holderafterlist[i]; after.Name = after.Name.Replace(" ", ""); if (after.Name == last.HolderFullName || after.Name == last.HolderShortName) { stockchangelist.Remove(last); //结构体,无法直接修改!!使用删除,增加的方法 last.HoldNumberAfterChange = after.Count; last.HoldPercentAfterChange = after.Percent; newRec.Add(last); } } } if (holderafterlist.Count != namelist.Count) { if (!Program.IsMultiThreadMode) { Program.Logger.WriteLine("增持者数量确认!"); } } stockchangelist.AddRange(newRec); return(stockchangelist); }
static List <struStockChange> ExtractFromTable(HTMLEngine.MyRootHtmlNode root, string id) { var StockHolderRule = new TableSearchRule(); StockHolderRule.Name = "股东全称"; StockHolderRule.Rule = new string[] { "股东名称" }.ToList(); StockHolderRule.IsEq = true; var ChangeDateRule = new TableSearchRule(); ChangeDateRule.Name = "变动截止日期"; ChangeDateRule.Rule = new string[] { "减持期间", "增持期间", "减持时间", "增持时间" }.ToList(); ChangeDateRule.IsEq = false; ChangeDateRule.Normalize = Normalizer.NormailizeDate; var ChangePriceRule = new TableSearchRule(); ChangePriceRule.Name = "变动价格"; ChangePriceRule.Rule = new string[] { "减持均价", "增持均价" }.ToList(); ChangePriceRule.IsEq = false; ChangePriceRule.Normalize = (x, y) => { if (x.Contains("元")) { return(Utility.GetStringBefore(x, "元")); } return(x); }; var ChangeNumberRule = new TableSearchRule(); ChangeNumberRule.Name = "变动数量"; ChangeNumberRule.Rule = new string[] { "减持股数", "增持股数" }.ToList(); ChangeNumberRule.IsEq = false; ChangeNumberRule.Normalize = Normalizer.NormalizerStockNumber; var Rules = new List <TableSearchRule>(); Rules.Add(StockHolderRule); Rules.Add(ChangeDateRule); Rules.Add(ChangePriceRule); Rules.Add(ChangeNumberRule); var result = HTMLTable.GetMultiInfo(root, Rules, false); //只写在最后一条记录的地方,不过必须及时过滤掉不存在的记录 result.Reverse(); var stockchangelist = new List <struStockChange>(); foreach (var rec in result) { var stockchange = new struStockChange(); stockchange.id = id; var Name = NormalizeCompanyName(rec[0].RawData); stockchange.HolderFullName = Name.Item1; stockchange.HolderShortName = Name.Item2; stockchange.ChangeEndDate = rec[1].RawData; stockchange.ChangePrice = rec[2].RawData; stockchange.ChangeNumber = rec[3].RawData; var holderafterlist = GetHolderAfter(root); for (int i = 0; i < holderafterlist.Count; i++) { var after = holderafterlist[i]; if (after.Used) { continue; } if (after.Name == stockchange.HolderFullName || after.Name == stockchange.HolderShortName) { stockchange.HoldNumberAfterChange = after.Count; stockchange.HoldPercentAfterChange = after.Percent; after.Used = true; break; } } stockchangelist.Add(stockchange); } return(stockchangelist); }
List <struIncreaseStock> GetMultiTarget(HTMLEngine.MyRootHtmlNode root, struIncreaseStock SampleincreaseStock) { var BuyerRule = new TableSearchRule(); BuyerRule.Name = "认购对象"; //"投资者名称","股东名称" BuyerRule.Title = new string[] { "发行对象", "认购对象", "发行对象名称" }.ToList(); BuyerRule.IsTitleEq = true; BuyerRule.IsRequire = true; var BuyNumber = new TableSearchRule(); BuyNumber.Name = "增发数量"; BuyNumber.Title = new string[] { "配售股数", "认购数量", "认购股数", "认购股份数", "发行股份数", "配售数量" }.ToList(); BuyNumber.IsTitleEq = false; //包含即可 BuyNumber.Normalize = NumberUtility.NormalizerStockNumber; var BuyMoney = new TableSearchRule(); BuyMoney.Name = "增发金额"; BuyMoney.Title = new string[] { "配售金额", "认购金额", "获配金额" }.ToList(); BuyMoney.IsTitleEq = false; //包含即可 BuyMoney.Normalize = MoneyUtility.Format; var FreezeYear = new TableSearchRule(); FreezeYear.Name = "锁定期"; FreezeYear.Title = new string[] { "锁定期", "限售期" }.ToList(); FreezeYear.IsTitleEq = false; //包含即可 FreezeYear.Normalize = NormalizerFreezeYear; var BuyPrice = new TableSearchRule(); BuyPrice.Name = "价格"; BuyPrice.Title = new string[] { "认购价格", "配售价格", "申购报价" }.ToList(); BuyPrice.IsTitleEq = false; //包含即可 BuyPrice.Normalize = MoneyUtility.Format; var Rules = new List <TableSearchRule>(); Rules.Add(BuyerRule); Rules.Add(BuyNumber); Rules.Add(BuyMoney); Rules.Add(FreezeYear); Rules.Add(BuyPrice); var result = HTMLTable.GetMultiInfo(root, Rules, true); var increaseStocklist = new List <struIncreaseStock>(); foreach (var item in result) { var increase = new struIncreaseStock(); increase.id = SampleincreaseStock.id; increase.BuyMethod = SampleincreaseStock.BuyMethod; increase.PublishTarget = item[0].RawData; if (String.IsNullOrEmpty(increase.PublishTarget)) { continue; } increase.PublishTarget = increase.PublishTarget.NormalizeTextResult(); increase.IncreaseNumber = item[1].RawData; if (!String.IsNullOrEmpty(increase.IncreaseNumber) && increase.IncreaseNumber.Equals("0")) { continue; } if (!String.IsNullOrEmpty(increase.IncreaseNumber) && increase.IncreaseNumber.Contains("|")) { increase.IncreaseNumber = increase.IncreaseNumber.Split("|").Last(); } increase.IncreaseMoney = item[2].RawData; if (!String.IsNullOrEmpty(increase.IncreaseMoney) && increase.IncreaseMoney.Equals("0")) { continue; } if (!String.IsNullOrEmpty(increase.IncreaseMoney) && increase.IncreaseMoney.Contains("|")) { increase.IncreaseMoney = increase.IncreaseMoney.Split("|").Last(); } //手工计算金额 if (String.IsNullOrEmpty(increase.IncreaseMoney)) { if (!String.IsNullOrEmpty(increase.IncreaseNumber)) { if (!String.IsNullOrEmpty(item[4].RawData)) { double price; if (double.TryParse(item[4].RawData, out price)) { double number; if (double.TryParse(increase.IncreaseNumber, out number)) { double money = price * number; if (!Program.IsMultiThreadMode) { Program.Logger.WriteLine("通过计算获得金额:" + money.ToString()); } } } } } } increase.FreezeYear = item[3].RawData; increaseStocklist.Add(increase); } return(increaseStocklist); }