Example #1
0
 public static StockCode Parse(string strCode)
 {
     if (strCode.Contains("."))
     {
         var code = new StockCode();
         code.Code     = strCode.Substring(0, strCode.IndexOf('.'));
         code.Exchange = strCode.Substring(strCode.IndexOf('.') + 1) == "SH" ? Exchange.SH : Exchange.SZ;
         return(code);
     }
     return(null);
 }
Example #2
0
        private void Compute()
        {
            var doc = web.Document as mshtml.HTMLDocument;

            if (doc == null)
            {
                Console.WriteLine("doc is null.");
                return;
            }
            IHTMLElement mainPanel = doc.getElementById("hqpanel");

            StockInfo si = new StockInfo();

            if (mainPanel == null)
            {
                // 读取错误。
                Console.WriteLine("读取错误。");
                return;
            }

            foreach (IHTMLElement child in mainPanel.children)
            {
                if (child.tagName.ToUpper() == "DIV")
                {
                    if (child.className.Contains("gb_title"))
                    {
                        si.Name = ((child.children[0] as IHTMLElement).children[0] as IHTMLElement).innerText;
                        si.Code = StockCode.Parse(((child.children[0] as IHTMLElement).children[1] as IHTMLElement).innerText);

                        lblMessage.Content = $"{pos}/{codeList.Count} {si.Name} {si.Code}";
                    }
                    else if (child.className.Contains("content"))
                    {
                        if ((child.children[0] as IHTMLElement).className.Contains("col-1 fl"))
                        {
                            var currentPrice = (((child.children[0] as IHTMLElement).children[1] as IHTMLElement).children[0] as IHTMLElement).innerText;                               // 价格
                            var upNumber     = ((((child.children[0] as IHTMLElement).children[1] as IHTMLElement).children[1] as IHTMLElement).children[0] as IHTMLElement).innerText; // 涨幅点数
                            var upPercentage = ((((child.children[0] as IHTMLElement).children[1] as IHTMLElement).children[1] as IHTMLElement).children[1] as IHTMLElement).innerText; // 涨幅比率
                            si.Price          = currentPrice;
                            si.ZhangFuDianShu = upNumber;
                            si.ZhangFuBiLv    = upPercentage.Replace("%", string.Empty);
                        }
                        if ((child.children[1] as IHTMLElement).className.Contains("col-2 fr"))
                        {
                            si.ZuoShou = (((((child.children[1] as IHTMLElement).children[0] as IHTMLElement)).children[0] as IHTMLElement).children[1] as IHTMLElement).innerText;                                   // 昨收
                            si.JinKai  = (((((child.children[1] as IHTMLElement).children[0] as IHTMLElement)).children[1] as IHTMLElement).children[1] as IHTMLElement).innerText;                                   // 今开
                            si.ZuiGao  = (((((child.children[1] as IHTMLElement).children[0] as IHTMLElement)).children[2] as IHTMLElement).children[1] as IHTMLElement).innerText;                                   // 最高
                            si.ZuiDi   = (((((child.children[1] as IHTMLElement).children[0] as IHTMLElement)).children[3] as IHTMLElement).children[1] as IHTMLElement).innerText;                                   // 最低

                            si.ChengJiaoLiang = (((((child.children[1] as IHTMLElement).children[1] as IHTMLElement)).children[0] as IHTMLElement).children[1] as IHTMLElement).innerText.Replace("手", string.Empty); // 成交量
                            if (si.ChengJiaoLiang.Contains("万"))
                            {
                                si.ChengJiaoLiang = (((Convert.ToDecimal(si.ChengJiaoLiang.Replace("万", string.Empty))) * 10000)).ToString();
                            }
                            si.ChengJiaoE = (((((child.children[1] as IHTMLElement).children[1] as IHTMLElement)).children[1] as IHTMLElement).children[1] as IHTMLElement).innerText; // 成交额
                            if (si.ChengJiaoE.Contains("万"))
                            {
                                si.ChengJiaoE = (((Convert.ToDecimal(si.ChengJiaoLiang.Replace("万", string.Empty))) * 10000)).ToString();
                            }
                            if (si.ChengJiaoE.Contains("亿"))
                            {
                                si.ChengJiaoE = (((Convert.ToDecimal(si.ChengJiaoLiang.Replace("亿", string.Empty))) * 100000000)).ToString();
                            }
                            si.ZongShiZhi    = (((((child.children[1] as IHTMLElement).children[1] as IHTMLElement)).children[2] as IHTMLElement).children[1] as IHTMLElement).innerText.Replace("亿", string.Empty); // 总市值
                            si.LiuTongShiZhi = (((((child.children[1] as IHTMLElement).children[1] as IHTMLElement)).children[3] as IHTMLElement).children[1] as IHTMLElement).innerText.Replace("亿", string.Empty); // 流通市值

                            si.HuanShouLv = (((((child.children[1] as IHTMLElement).children[2] as IHTMLElement)).children[0] as IHTMLElement).children[1] as IHTMLElement).innerText;                               // 换手率
                            si.ShiJingLv  = (((((child.children[1] as IHTMLElement).children[2] as IHTMLElement)).children[1] as IHTMLElement).children[1] as IHTMLElement).innerText;                               // 市净率
                            si.ZhenFu     = (((((child.children[1] as IHTMLElement).children[2] as IHTMLElement)).children[2] as IHTMLElement).children[1] as IHTMLElement).innerText;                               // 振幅
                            si.ShiYingLv  = (((((child.children[1] as IHTMLElement).children[2] as IHTMLElement)).children[3] as IHTMLElement).children[1] as IHTMLElement).innerText;                               // 市盈率
                        }
                    }
                }
            }
            si.Timestamp = DateTime.Now;
            WriteData(si);
        }